User input to repeat a script
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
trying to give users the ability to re-run a program with the following
while(1)
%%code
m = input('Enter Y to start over. Enter Quiz to move on to the Quiz: ','s');
if m==['Quiz']
break
end
end
next section of code is the quiz
This loop for some reason makes certain graphs not get displayed, and for the program to not run right. the code in the middle is like 200 lines, and runs perfect without the whileloop.
any suggestions on how i could alternatively accomplish this same task of giving the user the ability to start the script from the start again?
0 Commenti
Risposte (3)
Walter Roberson
il 11 Ott 2023
if strcmp(m, 'Quiz')
Remember that in MATLAB, characters with ' around them forms a character vector. 'Quiz' is, for many purposes in MATLAB, the same as uint16([81 117 105 122])
6 Commenti
Walter Roberson
il 11 Ott 2023
When you call "high level plotting commands" such as plot() or contour() or imshow() then by default they clear the current axes before drawing. You can use "hold on" to prevent that
Image Analyst
il 11 Ott 2023
Modificato: Image Analyst
il 11 Ott 2023
Try questdlg
while (1)
% Put script code here.
% Now ask use if they want to do it again.
promptMessage = sprintf('Do you want to run it again,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break.
end
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!