Subplot with matlab figures (.fig files)
이전 댓글 표시
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);
댓글 수: 3
Mahdi
2013년 3월 28일
It would be helpful if you post the error message that you get.
Javier Abanades
2013년 4월 3일
Javier Abanades
2013년 4월 3일
답변 (4개)
julien
2013년 4월 3일
0 개 추천
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));
Mike Garrity
2013년 4월 5일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!