Hi
I have written a code in a live editor and I want to make a while loop that whenever I run the code it starts from the begining and goes to the end and then goes back to the beginning of the code and run the whole code again and again continuosly until I break out the loop.
Can you please assist.
Cheers

5 件のコメント

KSSV
KSSV 2021 年 3 月 22 日
Show us the code.
Reza Tavakoli
Reza Tavakoli 2021 年 3 月 22 日
The code is a 250 lines code which does some calculation on something which is getting updated on realtime basis. No point to share the code.
What I need to know is how I can add a while loop to any code that can run the code from begining to the end again and again until I break that out manualy.
DGM
DGM 2021 年 3 月 22 日
Walter Roberson
Walter Roberson 2021 年 3 月 22 日
In the test I just did in R2020b, I created a very simple infinite while loop. The output for the first 10 disp() showed up, with the rest not being shown on the right (which is default in live script, the output is kept in a scrollable window.) When I clicked the Stop button, my MATLAB crashed. Repeatably.
Walter Roberson
Walter Roberson 2021 年 3 月 26 日
Mathworks says that the crash I mentioned above was a problem for R2020b, and has been fixed for R2021a. They said that the problem occurs when using disp() in a loop in Live Script, but does not occur if you just let MATLAB display the value by naming the variable without disp()

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

回答 (1 件)

Shivang Srivastava
Shivang Srivastava 2021 年 3 月 26 日

0 投票

As per my understanding of your query you need to execute your live script multiple times using a while loop. Here is a simple walk around using a while loop.
while 1
fprintf("Test1")
fprintf("Test2")
fprintf("Test3")
end
You may simply add a while 1 in the start for initializing an infinite loop and end to finish the while loop. You may even change the expression to fix the number of iterations as per requirement and for breaking you may use if statement along with break, or pressing Stop in the editor, or this way: https://www.mathworks.com/matlabcentral/answers/308386-create-keyboard-listener-to-interrupt-a-running-function

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

タグ

質問済み:

2021 年 3 月 22 日

コメント済み:

2021 年 3 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by