Matlab still busy a long time after last line of script is executed
42 views (last 30 days)
Show older comments
Gunther Breitenberger
on 15 Jul 2020
Commented: Adam Danz
on 17 Jul 2020
Summary: Script runs fine on first execution, Matlab stays busy very long after a subsequent execution of the exactly same script.
I am learning Matlab and am running a simple script with a couple of for- and if-loops and very small matrices (<1000 entries).
After first starting up Matlab and running the script it takes about 2 seconds to finish the script and the variables appear in the workspace shortly after. This leads me to believe that the code that I have is somewhat reasonable (no crazy infinite loops or anything like that...).
Then, after clearing the workspace, I do another, subsequent run of the same script without changing anything, the script executes in about 0.5s which is what I would expect.
However, after the last line is executed (in my case it is "toc"), Matlab remains busy for a solid 1-2 minutes. Only then, after this long time, the variables appear in the workspace again.
During all of this, I am monitoring CPU and RAM usage, and it stays well below 50% so I assume that is not the problem. What am I missing?
8 Comments
Accepted Answer
Adam Danz
on 16 Jul 2020
Edited: Adam Danz
on 16 Jul 2020
This is a known issue with Live Editor.
See this potential solution.
Note that the solution also mentions a point I made in the comments under your question. Make sure your script does not contain the command, "clear all".
2 Comments
Adam Danz
on 17 Jul 2020
Glad I can help.
If live editor is not needed, use a standard m-file instead. They are faster.
More Answers (0)
See Also
Categories
Find more on Debugging and Analysis 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!