Reputation: 25580
the question is how to plot two different plots simultaneously in matlab or octave.
I have loop, during execution in that loop there are data which should be plotted in two different plots. After execution of the loop I want to save these plots to disc.
How implement plotting in two different plots simultaneously?
As I understand, I should create somehow two different handles, then plot using these handles and finally save these plots using handles.
Any ideas how to do it?
UPDATE:
one more question: how to plot into the handler without showing of plot itself. I have lots of iterations in the loop, so it is annoying to close all windows with plots, when I just need them saved into files.
Upvotes: 2
Views: 3738
Reputation: 4221
I expanded a bit on @Pursuit's answer and added a more explicit loop where the data is created and plotted iterativly. Note that you could use figure() to create a new figure handle regardless of what you currently have active:
%Create figures, and set hold
f1 = figure(); hold on
f2 = figure(); hold on
%Variables for arbitrary loop
done = 0;
counter = 0;
n = 100;
while not(done)
%Activate figure 1 and plot
%figure(f1); %Comment in to switch between windows for each update
set(0,'CurrentFigure',f1) %Comment out if above line is used instead
plot(counter,rand,'r.')
%Activate figure 2
figure(f2);
plot(counter+10,rand*10,'ro');
counter = counter + 1;
if counter >= n
done = 1;
end
end
%Save figures
saveas(f1, 'figure_1.tiff','tiff');
saveas(f2, 'figure_2.tiff','tiff');
Upvotes: 4
Reputation: 12345
Try this:
fig1 = 1937612; %Random numbers unlikely to conflict with other figures already present
fig2 = 1073131;
for ix = 1:n
figure(fig1);
%Plot stuff here
saveas(fig1, ['figure_1_' num2str(ix) '.tiff'],'tiff'); %Note incrementing filenames
figure(fig2)
%Plot stuff here
saveas(fig2, ['figure_2_' num2str(ix) '.tiff'],'tiff'); %Note incrementing filenames
end
Upvotes: 2