Condition for if-statement not updating inside for-loop without pause function
Ältere Kommentare anzeigen
Hello!
I want to break from a for-loop when I close a plot. This is the code I use:
cscale = 100; %The number of colours in the colormap of choice
for c2 = 1:length(time)
f2 = figure(2);
p = plot(G);
G.Nodes.value = floor(real(cos(x(:,c2))+1)*((cscale-1)/2))+1; %scales x values to range from 1 up to cscale.
G.Edges.value = floor(real(cos(y(:,c2))+1)*((cscale-1)/2))+1; %scales y values to range from 1 up to cscale.
G.Nodes.NodeColors = G.Nodes.value;
G.Edges.EdgeColors = G.Edges.value;
p.NodeCData = G.Nodes.NodeColors;
p.EdgeCData = G.Edges.EdgeColors;
colormap(flipud(turbo(cscale)));
pause(1/5000);
if ~isgraphics(f2)
break;
end
end
The for-loop is not inside any other loop, so I shouldn't need to break more than once to end the code. The above only worked when I introduced the pause function, no matter how short the pause is. Note that I tried changing the condition to ~isgraphics(f1) where f1 is another figure generated earlier in the code (unlike f2, f1 is not generated inside a loop), and I also tried ishghandle and ishandle, but without the pause function, they all kept returning a logical 0 even after I closed the figure, and hence the code didn't break the loop. My question is why does it not work without pausing?
Any insight would be appreciated!
2 Kommentare
VBBV
am 21 Apr. 2024
Try with handle to plot function (without pause)
if ~isgraphics(p)
break;
end
Ahmed Amer Abdullah Zaid
am 21 Apr. 2024
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!