Function to utilize user input on a GUI system?

1 view (last 30 days)
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.

Accepted Answer

Riccardo Scorretti
Riccardo Scorretti on 21 Apr 2022
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

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!