Function to utilize user input on a GUI system?

조회 수: 1 (최근 30일)
Olivia Rose
Olivia Rose 2022년 4월 21일
답변: Riccardo Scorretti 2022년 4월 21일
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에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by