2012-01-03 42 views
1

问题是如何绘制两个不同的地块同时在matlab或八度。 我有循环,在循环执行过程中有数据应绘制在两个不同的情节。循环执行后,我想将这些图保存到光盘。
如何同时绘制两个不同的地块?
据我所知,我应该创建两个不同的手柄,然后绘制使用这些手柄,最后使用手柄保存这些图。
任何想法如何做到这一点?
更新:
还有一个问题:如何绘制到处理程序中而不显示绘图本身。我在循环中有很多迭代,所以当我只需要将它们保存到文件中时,关闭所有窗口和绘图是很烦人的。八度,matlab,绘制在两个不同的地块

回答

2

我扩大对@有点追求的答案,并加入其中,数据被创建和iterativly绘制一个更明确的循环。请注意,您可以使用figure()来创建一个新的图形句柄,而不管您目前有什么活动:

%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'); 
+0

如何绘制到处理程序而不显示绘图本身? – ashim 2012-01-04 02:21:00

+0

替换“图(f1);”在循环中:“set(0,'CurrentFigure',f1)”应该避免窗口一直弹出。 – Vidar 2012-01-04 05:26:39

+1

或者你可以“设置(f1,'Visible','off');设置(f2,'Visible','off')”,并在工作完成时将它们打开 – Batsu 2012-01-04 11:01:27

2

试试这个:

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