Matlab ignoring or executing lines out of order

9 次查看(过去 30 天)
I've been occasionally running into issues with Matlab apparently ignoring lines in a script. I'm using imagesc to plot a series of rasters in 5 subplots on each of two figures, and then adjusting the axes positions (axx contains axes object handles organized by figures [rows] and subplots [columns]):
for i = 1:5
axx(1,i).Position = [0.04+(i-1).*(axx(1,1).Position(3)+0.06) 0.18 0.12 0.7];
axx(2,i).Position = [0.04+(i-1).*(axx(2,1).Position(3)+0.02) 0.2 0.16 0.7];
end
About half the time when I run the full script, the positions for some of the axes simply don't change. However, if I copy just the for loop above into the command window after the full script fails, it works.
Matlab is not reporting any errors or warnings, and again, this doesn't seem to happen every time I run the script. When it does happen, however, it always affects the same subplots (the last three on the first figure, axx(1,3:5), which show no change in their 'Position' values).
I've also noticed that it doesn't seem to happen if I add a pause for a few seconds before or somewhere in the for loop, so I'm wondering if some kind of graphics-related lag is involved.
Does anyone have a clue what could be causing this, or what settings I could play around with to troubleshoot or solve it?
I'm having trouble providing an example script that can reproduce the issue without providing the large amounts of data the original uses, but in case it helps, I'm attaching an adapted version that sometimes (but again, not consistently!) does something similar. Instead of failing to move the axx(1,3:5) axes, this version instead occasionally fails to move the axx(2,1:3) axes. It's bulky because I haven't been able to get it to reproduce the problem at all if I try to simplify it any further.

采纳的回答

Image Analyst
Image Analyst 2023-8-5
Sometimes graphics don't update immediately, expecially if it's in a really computationally intensive loop. Try putting in
drawnow
whenever you want to force it to update the screen immediately.
  1 个评论
dpb
dpb 2023-8-9
Question subjects seem to come in bunches... :)
@Danica Roth, see @Steven Lord's (a TMW guru) comments to a <very similar problem raised only a little while ago>. Steve explains some of the "why" and "wherefore" causing the symptoms....but as @Image Analyst says, drawnow is the magic elixir.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by