Subplot with matlab figures (.fig files)
12 次查看(过去 30 天)
显示 更早的评论
if true
% code
endDear all,
I would like to plot 4 figures in the same plot using the function subplot.
I read this code on the website for 2 figures...
h1 = openfig('test1.fig','reuse'); % open figure
ax1 = gca; % get handle to axes of figure
h2 = openfig('test2.fig','reuse');
ax2 = gca;
s1 = subplot(2,1,1); %create and get handle to the subplot axes
s2 = subplot(2,1,2);
fig1 = get(ax1,'children'); %get handle to all the children in the figure
fig2 = get(ax2,'children');
copyobj(fig1,s1); %copy children to new parent axes i.e. the subplot axes
copyobj(fig2,s2);
I want to insert 4 figures, so I re-edit the code, but it did not work with the last figure, what is wrong with it?
h1 = openfig('154 withour.fig','reuse'); % open figure
ax1 = gca; % get handle to axes of figure
h2 = openfig('154 with.fig','reuse');
ax2 = gca;
h3 = openfig('315 without.fig','reuse'); % open figure
ax3 = gca; % get handle to axes of figure
h4 = openfig('315 with.fig','reuse'); % open figure
ax4 = gca; % get handle to axes of figure
% test1.fig and test2.fig are the names of the figure files which you would % like to copy into multiple subplots
s1 = subplot(2,2,1); %create and get handle to the subplot axes
s2 = subplot(2,2,2);
s3 = subplot(2,2,3);
s4 = subplot(2,2,4);
fig1 = get(ax1,'children'); %get handle to all the children in the figure
fig2 = get(ax2,'children');
fig3 = get(ax3,'children');
fig4 = get(ax4,'children');
copyobj(fig1,s1); %copy children to new parent axes i.e. the subplot axes
copyobj(fig2,s2);
copyobj(fig3,s3);
copyobj(fig4,s4);
回答(4 个)
julien
2013-4-3
if you want to plot 4 figues subplot(4,4,1) plot( T, f1(T)); %% fig 2 subplot(4,4,2) plot( T, f2(T));
%%%fig 3 subplot(4,4,3) plot( T, f3(T));
%% fig 4 subplot(4,4,4) plot( T, f4(T));
0 个评论
Mike Garrity
2013-4-5
Just guessing, but I don't see you creating a fifth figure after loading the four. Therefore, I would guess that the first call to subplot is deleting ax4.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!