Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How can I implement a dialog GUI in MATLAB?

1 visualizzazione (ultimi 30 giorni)
buxZED
buxZED il 2 Mar 2011
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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?

Risposte (3)

Paulo Silva
Paulo Silva il 2 Mar 2011
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.

Walter Roberson
Walter Roberson il 2 Mar 2011
See questdlg()

Matt Fig
Matt Fig il 2 Mar 2011
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 Commenti
Walter Roberson
Walter Roberson il 2 Mar 2011
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
Matt Fig il 2 Mar 2011
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...

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by