How print the loop iteration value each time to show progress of loop during a run
Show older comments
Hi All,
I am running a large dataset with various calculations for 4 dimensions (year (8), days (365), lat (266) and lon (245)) and i think it will take a really long time to run (maybe a few days), however during my debugging i found that sometimes the code would not move onto another iterations or take too long when there was an error. Therefore i want to see its progress in real time if possible, my loop is set out as for 1:8, dim2 (for 1:365), dim3.. etc. Is there a way of printing the loop iteration each time in the workspace? or maybe select a specific loop iteration i.e. year instead of selecting all of them? Let me know it will really help me track the progress of my run!
4 Comments
Dyuman Joshi
on 31 Aug 2023
You can unsuppress the output, use sprintf or fprintf or disp wherever you need check the values.
For large data sets, you can also put conditional checks in place to display the output if it satisfies the condition(s) put in place.
"however during my debugging i found that sometimes the code would not move onto another iterations or take too long when there was an error."
In which loop does it get stuck or takes too long time?
If it is in the innermost loop, then it might not be good idea to check the values for each iteration as you will have (atleast) 8*365*266*245 values.
Sophia
on 31 Aug 2023
Dyuman Joshi
on 31 Aug 2023
"I was thinking therefore if i could put intervals for it, 1:365 e.g. day 100, 200 and 300 etc? and then if it is passed it could print that as it=100 etc?"
That will definitely work.
"I had a look into sprintf and i found that i could use continue?"
No need to use continue here.
for n = 1:50
if mod(n,7)
disp(['Divisible by 7: ' num2str(n)]);
end
end
Also, since you have a big number of iterations, you might benefit from vectorizing part(s) of code - Vectorization
Sophia
on 5 Sep 2023
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!