Subplot with matlab figures (.fig files)
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (4)
julien
le 3 Avr 2013
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 commentaires
Mike Garrity
le 5 Avr 2013
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 commentaires
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!