如何使用for loop(matlab)对n个图形(pcolor)进行子绘图

如何使用for loop(matlab)对n个图形(pcolor)进行子绘图,matlab,matlab-figure,subplot,Matlab,Matlab Figure,Subplot,我已经保存了n个fig文件(所有的图形都是pcolor图形),我想在一个新的子图(n X 2)中绘制所有的图形。有人能帮我吗?我将非常感激:) 可以使用copyobj将现有轴的内容复制到目标轴。有关解释,请参见注释: N = 4; %% generate some figs fig = cell(1,N); for k = 1:N fig{k} = figure(k); fig{k}.Name = sprintf('fig_%i', k); pcolor(rand(1

我已经保存了n个fig文件(所有的图形都是pcolor图形),我想在一个新的子图(n X 2)中绘制所有的图形。有人能帮我吗?我将非常感激:)


可以使用
copyobj
将现有轴的内容复制到目标轴。有关解释,请参见注释:

N = 4;

%% generate some figs
fig = cell(1,N);

for k = 1:N
    fig{k} = figure(k);
    fig{k}.Name = sprintf('fig_%i', k);
    pcolor(rand(10));
    
    xlabel(sprintf('some xlabel %i',k))
    ylabel(sprintf('some ylabel %i',k))
    savefig(fig{k}, fig{k}.Name)
end


%% load figs and make nice subplot
fig_all = figure(99);clf;
for k = 1:N
    % load figure
    fig_tmp = openfig(sprintf('fig_%i', k),'invisible');
    % set fig_all as the current figure again
    figure(fig_all);
    % create target axes
    ax_target = subplot(N/2,2,k);
    pcolor(ax_target, rand(5)*0.001); cla; % plot some random pcolor stuff to setup axes correctly

    % get the source data and copy to target axes
    ax_src = fig_tmp.Children;
    copyobj(ax_src.Children, ax_target);
    % set axes properties of target to those of the source
    ax_target.XLim = ax_src.XLim;
    ax_target.YLim = ax_src.YLim;
    
    % copy the axes labels
    ax_target.XLabel.String = ax_src.XLabel.String;
    ax_target.YLabel.String = ax_src.YLabel.String;
end

欢迎使用堆栈溢出!请拿起这本书,仔细阅读。不清楚您希望我们做什么,尤其是您在此处发布的代码的作用。请您澄清问题,并将代码修改为a,即演示我们可以运行的问题的代码。因此,请提供示例输入(可能是两个.fig文件,您可以使用随机数据创建这些文件)和示例输出(可能是带有两个子批次的图形)help@SunSer你有错误吗?什么不起作用?请描述什么不起作用,不要在注释中发布代码(根本不可读)。你可以回答你的问题并添加新信息。你能看到我的答案吗?
N = 4;

%% generate some figs
fig = cell(1,N);

for k = 1:N
    fig{k} = figure(k);
    fig{k}.Name = sprintf('fig_%i', k);
    pcolor(rand(10));
    
    xlabel(sprintf('some xlabel %i',k))
    ylabel(sprintf('some ylabel %i',k))
    savefig(fig{k}, fig{k}.Name)
end


%% load figs and make nice subplot
fig_all = figure(99);clf;
for k = 1:N
    % load figure
    fig_tmp = openfig(sprintf('fig_%i', k),'invisible');
    % set fig_all as the current figure again
    figure(fig_all);
    % create target axes
    ax_target = subplot(N/2,2,k);
    pcolor(ax_target, rand(5)*0.001); cla; % plot some random pcolor stuff to setup axes correctly

    % get the source data and copy to target axes
    ax_src = fig_tmp.Children;
    copyobj(ax_src.Children, ax_target);
    % set axes properties of target to those of the source
    ax_target.XLim = ax_src.XLim;
    ax_target.YLim = ax_src.YLim;
    
    % copy the axes labels
    ax_target.XLabel.String = ax_src.XLabel.String;
    ax_target.YLabel.String = ax_src.YLabel.String;
end