Matlab code runs sometimes and sometimes does not

5 ビュー (過去 30 日間)
Nitish Ponkshe
Nitish Ponkshe 2023 年 2 月 8 日
コメント済み: Nitish Ponkshe 2023 年 2 月 14 日
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 Center および File ExchangeCreating, 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