rerun code using if statement

조회 수: 8 (최근 30일)
ReeceOD
ReeceOD 2018년 2월 23일
답변: Image Analyst 2018년 2월 23일
how can I rerun a code once it's finished? in order to type in new values.
I'd like an if statement at the end of my code asking the user whether they want the code to rerun and then have it restart.
Thanks

채택된 답변

Image Analyst
Image Analyst 2018년 2월 23일
Try this:
numIterations = 1;
maxIterations = 20;
while numIterations < maxIterations
% Run your code now....
% Now ask user if they want to run it again.
promptMessage = sprintf('Do you want to process again,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Process Again', 'Quit', 'Process Again');
if contains(buttonText, 'Quit')
break; % Break out of the while loop.
end
numIterations = numIterations + 1;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by