八度,matlab,绘制两个不同的图

发布于 2024-12-23 18:20:29 字数 273 浏览 3 评论 0原文

问题是如何在 matlab 或 Octave 中同时绘制两个不同的图。 我有循环,在该循环执行期间,有一些数据应该绘制在两个不同的图中。执行循环后,我想将这些图保存到光盘上。
如何同时在两个不同的图中实现绘图?
据我了解,我应该以某种方式创建两个不同的句柄,然后使用这些句柄进行绘图,最后使用句柄保存这些绘图。
有什么想法如何去做吗?
更新:
还有一个问题:如何在不显示绘图本身的情况下绘制到处理程序中。我在循环中有很多迭代,所以当我只需要将它们保存到文件中时,关闭所有带有绘图的窗口很烦人。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

篱下浅笙歌 2024-12-30 18:20:29

我对 @Pursuit 的答案进行了一些扩展,并添加了一个更明确的循环,其中数据被迭代地创建和绘制。请注意,无论当前有什么活动,您都可以使用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'); 

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'); 
无言温柔 2024-12-30 18:20:29

试试这个:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文