Code runs very slow after making small changes
11 次查看(过去 30 天)
显示 更早的评论
I have a script containing ~1500 lines that I run in sections as each section produces a different plot. If I run from scratch after clearing everything, each section runs as expected, taking 20-30 seconds each. However, if I make any change (e.g. something as small as changing the colours in a plot), it then gets stuck. Rather than taking 20-30 seconds, a section could take over 2 minutes. I realised this was occuring specifically after making changes, so I started running single lines of code to see what was happening. I would enter something simple like x=1; into the command window and this would take a minute or two to complete (which obviously is ridiculous). However, once I had done this, it was as if it had reset, and everything then started running normally again - until I made another change.
I've tried shutting Matlab down and restarting the computer, but the problem persists. It has been like this for about a month now, I've got into a habbit of typing x=1; into the command window after every change I make so I know whether Matlab is ready for me to run the actual script again. Sometimes it isn't too bad, and will only take about 10 seconds, but other times I can be waiting for 5 minutes.
For extra context, this only happens when I am working on scripts that use a fair bit of memory. The one I mention in this example reads in ~500mb of data and also does MCMC analysis with ~200,000 samples.
8 个评论
Víctor Wilfried Staels
2024-9-3
移动:Walter Roberson
2024-9-3
Hi @hg24 Did you manage to solve your problem? I have the same one. Even writing down in the command window "2+2" will cause a huge execution time after changing something in the script. I wonder if this is related to some backgroud checking MATLAB is doing when the script changes, like the license check or something like that.
Walter Roberson
2024-9-3
One of the causes of MATLAB taking a long time between trivial statements, is if the search path contains a network drive, and the network drive is slow or hung.
回答(1 个)
Constantino Carlos Reyes-Aldasoro
2024-3-7
Are you plotting your results? If you are, and you are doing many of these, it may be the case that that is what is slowing down your code if every time you are using plot(...). I once had problem like that and solved it by plotting once, grabbing the handle of the plot and then changing the XData and YData of the handles. Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!