필터 지우기
필터 지우기

Subplot with matlab figures (.fig files)

조회 수: 12 (최근 30일)
Javier Abanades
Javier Abanades 2013년 3월 28일
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
Javier Abanades
Javier Abanades 2013년 4월 3일
Error using handle.handle/get Invalid or deleted object.
Error in Multiplot (line 21) fig4 = get(ax4,'children');
But I cannot understand why the function get does not work with the fig4 if it works with the rest of figures....
Matlab prints the first figure, the second and the third one but with the four fails...
I do not know why... any idea?
Regards Javier
Javier Abanades
Javier Abanades 2013년 4월 3일
This is the topic with the answer to inster figures with subplot

댓글을 달려면 로그인하십시오.

답변 (4개)

Javier Abanades
Javier Abanades 2013년 4월 3일
This is the error I get...
Error using handle.handle/get Invalid or deleted object.
Error in Multiplot (line 21) fig4 = get(ax4,'children');
I do not understand why works for every figure and get an error for the last one

julien
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));

Javier Abanades
Javier Abanades 2013년 4월 3일
But you need to open the figures first and select the axis of the figure.
Besides, if you use subplot (4,4,1) you will charge 16 spaces for the figures...

Mike Garrity
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.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by