Condition for if-statement not updating inside for-loop without pause function
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!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! 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! figure, plot, break, if statement, loop, pause MATLAB Answers — New Questions