gpt4 book ai didi

matlab - 如何使用 for 循环 (matlab) 绘制 n 个图形 (pcolor)

转载 作者:行者123 更新时间:2023-12-05 07:00:26 28 4
gpt4 key购买 nike

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

    % Open each figure and copy content
for i = 1:nFig
% Open fig-i
filename = fullfile(rep,list(i).name);
fighand = openfig(filename,'invisible');

h=subplot(nFig,2,i);


% Close fig-i
close(fighand)
end

最佳答案

您可以使用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

enter image description here

关于matlab - 如何使用 for 循环 (matlab) 绘制 n 个图形 (pcolor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64134314/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com