Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I implement a dialog GUI in MATLAB?
1 次查看(过去 30 天)
显示 更早的评论
task_complete=0;
while task_complete==0
disp(' ')
disp('1:Q1')
disp('2:Q2')
P_Switch = input ('Enter Question Number:');
switch P_Switch
case 1
clear
disp('solve Q1')
P1
case 2
clear
disp('solve Q2')
P2
end
disp(' ')
task_complete=input(' Correct Solution? yes=1, no=0:');
end
Can I get this to be a dialog box with eye candy buttons instead of text?
0 个评论
回答(3 个)
Paulo Silva
2011-3-2
Yes you can, how?
1-create a figure
2-create two buttons
3-create text box for the questions and info
4-create edit box for the input
5-add your code
Using GUIDE that's super easy, doing it without GUIDE is only a little harder.
0 个评论
Matt Fig
2011-3-2
Something like this:
task_complete='No';
while strcmp(task_complete,'No')
C = questdlg('Choose question to solve:', ...
'Select a question', ...
'1','2','1');
switch C
case '1'
P1
case '2'
P2
end
task_complete = questdlg('Are we done?', ...
'Finished?', ...
'Yes','No','Yes');
end
2 个评论
Walter Roberson
2011-3-2
Matt's solution closely follows the logic of the original question. Neither the original question nor Matt's solution will explicitly recognize that some other value than 1 or 2 has been chosen, a chase that _probably_ should not ask the 'Done' question but should instead go back to asking the question again.
The way to recognize other data as having been entered is to use a default section in the switch statement.
(Specifically, if the user clicks on the Close button or on the Cancel button, the result of questdlg() will be the empty string. The default value that Matt provided, the '1', is used only if the user presses Return.)
Matt Fig
2011-3-2
Yes, I recognized that too. It will be up to buxZED to define the behavior of the program in case the user opts out at the dlg. Does it quit? Does it keep pestering with a dialog? Only buxZED knows...
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!