Matlab ignoring or executing lines out of order
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 5 Aug. 2023
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 Kommentar
dpb
am 9 Aug. 2023
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!