user1578688
user1578688

Reputation: 427

Close/pause process in Matlab

I have a code with a lot of plots. The problem (excuse my ignorance because I don't know if it's possible) is, for example, when I execute since the beginning, I directly see the last plot, not one after the other. So, for example, I've tried this but it doesn't work at all:

pause(2); %After two seconds it starts and open the plot but I directly see the last plot, not this    
plot (x, y);
title ('Average values')
close; % The command close it works but only if I press 'evaluate function'

pause(2);
plot (out1,out2);
close;

Also, I've tried with the keyboard command to try if it's possible to close the plot with one key and then, open the other with another key but I couldn't do it.

If someone knows how can I do it I will be so I'll be so grateful,

Upvotes: 0

Views: 1322

Answers (2)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

I may misunderstand what you are trying to do, but when i try to create what you describe it just works for me as expected. Here is my example:

Note that you will want to close any open figure windows to ensure that it pops up rather than letting it stay in the background.

pause(2); % Wait 2 seconds before starting
plot(1:10); % Plot an upward line
title('up'); % Give it a title

pause(2); % Wait 2 seconds before showing the next plot
plot(10:-1:1); % Plot an downward line
title('down'); % Give it a title

Depending on how you want to use them, saving the plots may be a nicer solution.

Upvotes: 0

bdecaf
bdecaf

Reputation: 4732

Matlab does plotting and the calculation typically in the same process. So typically you will not get anything displayed till there is some spare time for plotting in your program.

To force matlab to redraw the windows you can use the drawnow command. But it only draws exactly at the moment - so if your figure window would be hidden or behind some other window, the redrawing when it comes to foreground will not happen till the next time.

In your case you also close the plot before the pause (where it could be displayed). So if you'd exchange the two commands you should see it. The obvious drawback of the pause is - it halts your program for the time.


from my experience I would suggest you rather save the plots as graphic files and use some external program to view them. Also I find the popping up new windows annoying and interrupting my workflow - so I would reuse the graphic window, by just clearing it with clf.

Upvotes: 1

Related Questions