【问题标题】:how to subplot n figures (pcolor) using for loop (matlab)如何使用for循环(matlab)对n个数字(pcolor)进行子图绘制
【发布时间】:2021-01-15 22:23:29
【问题描述】:
我有 n 个保存的 fig 文件(所有数字都是 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
【问题讨论】:
标签:
matlab
matlab-figure
subplot
【解决方案1】:
您可以使用copyobj 将现有坐标区的内容复制到目标坐标区。解释见 cmets:
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
【讨论】:
-
@SunSer 你有错误吗?什么不起作用?请描述什么不起作用,并且不要在 cmets 中发布代码(根本不可读)。您可以edit您的问题并在那里添加新信息
-