produce a code for GUI

10 ビュー (過去 30 日間)
Lim Xiao Hui
Lim Xiao Hui 2021 年 6 月 15 日
回答済み: Aashray 2025 年 8 月 22 日 5:52
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.

回答 (1 件)

Aashray
Aashray 2025 年 8 月 22 日 5:52
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:
  1. inputdlg”: https://www.mathworks.com/help/matlab/ref/inputdlg.html
  2. “str2double”: https://www.mathworks.com/help/matlab/ref/str2double.html

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by