Function to utilize user input on a GUI system?

1 次查看(过去 30 天)
This is the first time I've had to make a gui and I'm not sure how to fix this. I have an edit box to be used by the user to input a value, then a push button is used that sets off the calculations, then graphs and answers are displayed. I have everything working expect for the input. I thought the input part was working but apparently not, and I realize I'm not sure how to go about it.
m=input('Please provide the weight of the particle: \n');
That's the original code, but I need it translated so that it works within the gui correctly.

采纳的回答

Riccardo Scorretti
Riccardo Scorretti 2022-4-21
If you want to ask such a question by a GUI dialog, you can use the function inputdlg. For instance:
m = inputdlg('Please provide the weight of the particle', 'Settings');
m = str2num(m{1})
Then, when using GUI you ough to take into account the case when the user cancels the operation, for instance:
m = inputdlg('Please provide the weight of the particle', 'Settings');
if isempty(m)
msgbox('Operation cancelled by the user');
return
else
m = str2num(m{1})
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by