【问题标题】:How to switch between subplots of different figures inside a for loop in MATLAB如何在MATLAB中的for循环内切换不同图形的子图
【发布时间】:2015-04-13 21:32:10
【问题描述】:

考虑下面的代码sn-p,

%% Declare figures
figure(1); % Plot Measured (y) Vs Reference(x) data for 6 cases
figure(2); % Plot Regression fit for Measured vs Reference for 6 cases

%% Run algorithm for 6 cases
for i=1:6
:
:
subplot(3,2,i);plot(x,y); % should go to figure 1
:
linearfittype = fittype({'0','x','1'});
f = fit(f,x,y);
subplot(3,2,i);plot(f,x,y); % should go to figure 2
end

如何将子图分配给适当的数字?

【问题讨论】:

    标签: matlab matlab-figure subplot


    【解决方案1】:

    如果我理解正确,在subplot 语句之前写figure(1)figure(2) 就足够了。

    如果h 是现有图窗的句柄或 Number 属性值,则figure(h) 使该现有图窗成为当前图窗,使其可见,并将其移动到屏幕上所有其他图窗的顶部。当前图形是图形输出的目标。

    所以:

    %% Declare figures
    figure(1); % Plot Measured (y) Vs Reference(x) data for 6 cases
    figure(2); % Plot Regression fit for Measured vs Reference for 6 cases
    
    %% Run algorithm for 6 cases
    for i=1:6
    :
    :
    figure(1) %// make figure 1 the current figure
    subplot(3,2,i);plot(x,y); %// should go to figure 1
    :
    linearfittype = fittype({'0','x','1'});
    f = fit(f,x,y);
    figure(2) %// make figure 2 the current figure
    subplot(3,2,i);plot(f,x,y); %// should go to figure 2
    end
    

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 2016-02-09
      • 1970-01-01
      • 2016-09-29
      • 2021-04-17
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      相关资源
      最近更新 更多