How to know which loop is being calculated?

8 visualizaciones (últimos 30 días)
Wolfgang McCormack
Wolfgang McCormack el 12 de Abr. de 2021
Respondida: Matt J el 12 de Abr. de 2021
Hi all,
I have a k = 1:100 and j = 1:500 where the second one is loop within the first loop. How can I find out which loop is being calculated when I click run? For instance, I want to know after 20 minutes of running, is MATLAB running the first loop k=1 and j =250? or is it k=1 and j=10? I want to know which loop is being calculated.
Thanks

Respuesta aceptada

SungJun Cho
SungJun Cho el 12 de Abr. de 2021
Hello,
To find out which step the loop is processing, you can always click pause and check "k" and "j".
However, you can also add few lines of command to automatically inform you the process.
For example,
for k = 1:100
if mod(k,10) == 0
fprintf(['Processed: k=' num2str(k) '\n']);
end
for j = 1:500
if mod(j,50) == 0
fprintf(['j=' num2str(j) ' processed \n']);
end
end
end
the above code will give you the value of "k" whenever it becomes the multiple of 10 (i.e. 10, 20, 30, and so on) and the value of "j" when it becomes the multiple of 50.
Hope this helps!
Best,
SungJun

Más respuestas (2)

Matt J
Matt J el 12 de Abr. de 2021
One way is to click pause, then hover the mouse overk and j in the Matlab Editor.

Matt J
Matt J el 12 de Abr. de 2021

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by