Drawing figure in a for loop
Mostrar comentarios más antiguos
Hello all,
I have a for loop and I want to see the progress of the figure as the loop goes. Basically the code is like this:
SNRdB=0:20;
nErr=zeros(length(SNRdB),1);
for ii=1:length(SNRdB)
...
nErr(ii)=...
figure(1)
semilogy(SNRdB,nErr)
end
However, when I write it this way the figure is halted during the next loop and I cannot see it. How can I see the figure freely while the loop is running?
Thanks
7 comentarios
Geoff Hayes
el 21 de Jun. de 2014
Do you mean halted on the next iteration of the loop ( ii==2 ), or do you have a subsequent loop that follows the one above?
And what exactly do you mean by halted? Does the figure stop updating (freeze with plot from previous iteration)? When the loop exits, does the figure refresh with the last known plot?
Geoff Hayes
el 21 de Jun. de 2014
An alternative may be to save the figure to an image file which you could then view in some other application
h = figure(1);
semilogy(SNRdB,nErr);
saveas(h,'semilogyFigure','jpg');
Star Strider
el 21 de Jun. de 2014
@Geoff — I think that defeats the purpose of seeing it in real-time!
Geoff Hayes
el 21 de Jun. de 2014
Right…but since it is minimized, your not really looking at the figure anyway. I took "minimized to the task bar" to mean that the figure was not visible at all and only available if you clicked it from the task bar.
I also understood "Each for loop takes too long (more than 15 minutes)" to mean that each iteration of the for loop takes 15 minutes to complete…given that the code only shows one for loop. I may have misunderstood that! :)
Star Strider
el 21 de Jun. de 2014
Minimising it seems to be the problem.
Geoff Hayes
el 21 de Jun. de 2014
Right - and S. is minimizing it because he has other stuff to do and doesn't want to see that figure or have it occupy area on his screen. Only at some point later does S. want to review the figure to check the progress by "retrieving the figure frame from the task bar".
Respuestas (2)
Star Strider
el 21 de Jun. de 2014
0 votos
2 comentarios
S. David
el 21 de Jun. de 2014
Star Strider
el 21 de Jun. de 2014
Editada: Star Strider
el 21 de Jun. de 2014
Nothing in the UI functions offers a solution, unfortunately.
My only suggestion is to not minimise it to the taskbar but position the figure off to the side, and then click on it when you want to see it. This is my usual strategy, but then I don’t know what’s on your desktop or how it’s organised.
You can also bring it to the foreground by clicking on it on the toolbar even when it’s not minimised. If you don’t minimise it, you may avoid the problem entirely.
Image Analyst
el 21 de Jun. de 2014
0 votos
Why are you calling figure(1) at all? Just get rid of it. You can use maxfig (in MATLAB Central) to get the window state and if it's not minimized, call drawnow after you call plot.
6 comentarios
Star Strider
el 21 de Jun. de 2014
The problem is that he minimises it to the Taskbar. (See OP’s first comment to my Answer.)
Image Analyst
el 21 de Jun. de 2014
Why is that a problem? Are you saying that the entire program comes to a screeching halt once it's minimized? He said drawnow works as long as it's not minimized so if you detect that and not call drawnow when it's minimized like I suggested, wouldn't that work? It should work if the drawnow was the problem. It won't work if the program totally pauses if it gets minimized.
Star Strider
el 21 de Jun. de 2014
I believe the problem is that the figure doesn’t update when it’s minimized. OP wants it to.
S. David
el 22 de Jun. de 2014
Image Analyst
el 22 de Jun. de 2014
Star Strider
el 22 de Jun. de 2014
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!