produce a code for GUI
Mostra commenti meno recenti
Hello can i ask if i want to plot a x-y graph in GUI with below condition
constant x=[0,0.02,0.05],
let user insert input y=[num, num, num] and then plot (x,y)
how about the code should i write? Thank you for your reply.
Risposte (1)
Aashray
il 22 Ago 2025
If you just need a quick way for the user to enter three numbers for y and then plot against the fixed x = [0 0.02 0.05], you can use “inputdlg” to prompt for values and then plot them as in the below code:
X = [0 0.02 0.05];
answ = inputdlg({'Y(1):','Y(2):','Y(3):'}, 'Enter Y values', 1, {'0','0','0'});
if ~isempty(answ)
Y = str2double(answ);
figure; plot(X,Y,'o-','LineWidth',1.5); grid on;
xlabel('x'); ylabel('y'); title(sprintf('X=[0 0.02 0.05], Y=[%g %g %g]',Y));
end

When you run this, MATLAB will show a dialog with three boxes for the user to enter values of “Y(1)”, “Y(2)”, “Y(3)”. After clicking OK, it will plot those points against [0 0.02 0.05].
You can refer to the below attached documentation links for reference:
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!