Matlab still busy a long time after last line of script is executed

42 views (last 30 days)
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
Gunther Breitenberger
Gunther Breitenberger on 16 Jul 2020
Hi Bruno, I don't create any graphic object.
It seems to me like the issue is somehow caused by the output window.
Clearing the output window (Clear All Output) before a rerun of the script will reduce the busy time from from 190s to 14s.
So the situation presents itself like this:
Fresh Matlab startup and running script: 8s busy
Rerunning script: 190s busy
Rerunning script with clearing workspace: 190s busy
Rerunning script with clearing output window: 14s busy
Adam Danz
Adam Danz on 16 Jul 2020
ahhhh...... so you're using Live Editor. That's an important detail.

Sign in to comment.

Accepted Answer

Adam Danz
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".

More Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!