我的程序在命令周期中产生小数字。有没有办法只保存这些数字,然后将它们合并到一个图中?
答案 0 :(得分:17)
考虑代码:
hFig = figure;
%# create temporary subplots as template
for i=1:2, h(i) = subplot(2,1,i); end %# create subplots
pos = get(h, 'Position'); %# record their positions
delete(h) %# delete them
%# load the .fig files inside the new figure
fileNames = {'a.fig' 'b.fig'}; %# saved *.fig file names
for i=1:2
%# load fig
hFigFile = hgload( fileNames{i} );
%# move/copy axis from old fig to new fig
hAx = get(hFigFile, 'Child'); %# hAx = gca;
set(hAx, 'Parent',hFig)
%#hAx = copyobj(hAx,hFig);
%# resize it to match subplot position
set(hAx, 'Position',pos{i});
%# delete old fig
delete(hFigFile)
end
改编的
答案 1 :(得分:1)
答案 2 :(得分:1)
我在这里作为一个例子答案:
h1 = figure(1)
plot(1:10,'o-r');
title('title');
xlabel('xlabel');
ylabel('ylabel');
% Copy contents
ch(1) = copyobj(gca,gcf);
% Figure 2
h2 = figure(2)
plot(1:30,'o-r');
title('title fig2');
xlabel('xlabel');
ylabel('ylabel');
% copy contents
ch(2) = copyobj(gca,gcf);
figure(3)
sh = subplot(1,2,1);
clear axes
p = get(sh,'position');
ah = copyobj(ch(1),gcf);
set(ah,'position',p);
% Create axis template
sh = subplot(1,2,2);
clear axes
p = get(sh,'position');
ah = copyobj(ch(2),gcf);
set(ah,'position',p);
% Delete template
% delete(sh);
答案 3 :(得分:1)
Amro's solution效果很好,但是使用箱形图你必须重置Xtick和Xtick标签,否则,由于某些原因,它们不会根据子图调整大小。当您创建箱图时或打开图后添加:
set(gca,'XTick',<1d vector>,'XTickLabel',<1d cell vector>)
或自动刻度和标签
set(gca,'XTickMode','auto','XTickLabelMode','auto')