Matlab code runs sometimes and sometimes does not

8 次查看(过去 30 天)
Hello all,
I have written a matlab script that calls multiple user-defined functions for various computations. I create figure objects within the main script, then some of the user-defined functions plot in the existing figure object (used proper hold on and off so that different functions plot on the same figure as needed). However, sometimes the script runs, creates all figures correctly with all the information but I keep getting busy prompt in matlab and the variables and matrices in the main script do not get populated in the workspace. Only by stopping the main script, I get the workspace filled up. Then sometimes when I clc, clear all, close all and re-run the script I get all figures and all variables and matrices defined in the main script correctly without delay. The whole process is more consistent when I don't plot any figure (The script always runs and workspace gets filled). Any idea for this kind of behavior (sometimes runs, next time might)?
  2 个评论
DGM
DGM 2023-2-8
Sounds to me more like something is causing a prolonged delay rather than it simply not running. Whether that's caused by the script or not is something that can't really be known without seeing the script.
Using clear all instead of clearvars is typically not necessary and can lead to slowdowns
... though I'm not sure if that command is normally part of your script.
Depending on how graphics objects are created, it's possible to have race conditions that may be caused by an object not existing before it's existence is required. The consequences of such a scenario depends entirely on what the code is doing.
Nitish Ponkshe
Nitish Ponkshe 2023-2-14
Thanks a lot for your reply. I do not use clear all as part of the script. I use it between runs of the code. It might be tricky for me to share my script and functions since I am in the process of using its results in a paper. But I'll get back to you soon if I can.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by