【问题标题】:replace old plot by new one用新地块替换旧地块
【发布时间】:2014-04-06 06:45:38
【问题描述】:

让我们考虑下面的代码

function [order]=find_order(y,fs);
order=0;
n=length(y);
n1=nextpow2(n);
ndft=2^n1;
for i=1:floor(n/2)
    [Pxx,f]=pburg(y,i,ndft,fs);
  % subplot(floor(n/2),floor(n/2),i);
   %subplot(ndft,ndft,i);
   h = figure; 
    plot(f,Pxx);
    title(['order',num2str(i),'i']);
    filename = 'mydata';
print(h, '-dpsc', filename);
    order(i)=i;    
    pause(6.21);
end
end

我有一个问题想要而不是在每次迭代时绘制新图,用新图替换旧图,那么我该怎么做呢?请帮助我

【问题讨论】:

    标签: matlab plot subplot


    【解决方案1】:

    在您的 for 循环中,您在每次迭代中使用 h = figure 调用一个新图形。如果您真的想保留函数调用,请将其移至 for 循环之外

    function [order]=find_order(y,fs);
    order=0;
    n=length(y);
    n1=nextpow2(n);
    ndft=2^n1;
    

    h = figure;

    for i=1:floor(n/2)
        [Pxx,f]=pburg(y,i,ndft,fs);
      % subplot(floor(n/2),floor(n/2),i);
       %subplot(ndft,ndft,i);
    
        plot(f,Pxx);
        title(['order',num2str(i),'i']);
        filename = 'mydata';
    print(h, '-dpsc', filename);
        order(i)=i;    
        pause(6.21);
    end
    end
    

    【讨论】:

    • 是否可以将每张图片保存在一个word文档中而不输出?
    猜你喜欢
    • 2016-06-04
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2021-08-29
    • 2017-06-28
    • 1970-01-01
    相关资源
    最近更新 更多