How to force a matlab script to rerun the script from the beginning using list items and if statement?

56 ビュー (過去 30 日間)
Helly everyone,
I have the following code:
% Here is the Main Code that does stuff
% After the code has done some stuff the user is left with three options:
list = {'text1','text2','RERUN_SCRIPT'};
[indx] = listdlg('SelectionMode','single','ListString',list);
% with the following if statements
if indx == 1
% code for importing works
end
if indx == 2
% code for deleting unwanted external files work
end
if indx == 3
% I cannot find a direct method to start the script again.
end
Also there is one problem: While my list is active I cannot edit my figure in the main code. Is there an option, even by default, allow an active edit of figures, etc. while list is active?

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 3 月 4 日
編集済み: Cris LaPierre 2021 年 3 月 4 日
Scripts execute from top to bottom. MATLAB does not have a GOTO command. However, you can accomplish this by reorganzing your code. For example, consider putting all the code you want to rerun inside a while loop, and repeat that loop as long indx==3.
indx == 3
while indx == 3
% After the code has done some stuff the user is left with three options:
list = {'text1','text2','RERUN_SCRIPT'};
[indx] = listdlg('SelectionMode','single','ListString',list);
% Use a switch statement. The loop will continue execution as long as the user selects 'rerun'
switch indx
case 1
% code for importing works
case 2
% code for deleting unwanted external files work
end
end
  4 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 3 月 4 日
For 1 and 2, I suggest learning more about how switch statements work. You define cases, and use the switch to set which case executes. If no case matches the switch, nothing is executed.
For 3, I'm not sure. I'm comfortable saying that when a user dialog is displayed, it is given focus. There may be a way to override this, but it's not something I have experience with. I'd suggest posting that as its own question and seeing if anyone else can help.
David Mrozek
David Mrozek 2021 年 3 月 4 日
Ok will take a look at the switch statements in general in isolate the 3rd question as a new one.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by