Concatenate figures in matlab, link figures in Matlab

Опубликовано: 08 Апрель 2026
на канале: Shck Tchamna (Ca᷅mnà')
7,622
55

link figures matlab.

% 1) Load saved figures

firstfig=hgload('fig1.fig');
secondfig=hgload('fig2.fig');

% 2) Prepare subplots
figure
h(1)=subplot(1,2,1);
h(2)=subplot(1,2,2);

% 3) Paste figures on the subplots
copyobj(allchild(get(firstfig,'CurrentAxes')),h(1));
copyobj(allchild(get(secondfig,'CurrentAxes')),h(2));


% % 4) Add legends to the new plot
% %
l(1)=legend(h(1),'Force','Energy')
l(2)=legend(h(2),'Moment','Sales')
%%
% % Now we want all the plots to be on one figure

% 1) Load saved figures

firstfig=hgload('fig1.fig');
secondfig=hgload('fig2.fig');

% 2) Prepare subplots

figure
h(1)=subplot(1,1,1);
% h(2)=subplot(1,2,2);

% 3) Paste figures on the subplots

copyobj(allchild(get(firstfig,'CurrentAxes')),h(1));
% copyobj(allchild(get(secondfig,'CurrentAxes')),h(1));
copyobj(allchild(get(secondfig,'CurrentAxes')),h(1));


% copyobj(allchild(firstfig), h(1))
% copyobj(allchild(secondfig), h(2))

% copyobj(allchild(get(firstfig)),h(1));
% copyobj(allchild(get(secondfig)),h(2));
% Add legends
%
% %

l(1)=legend(h(1),'Force','Energy','Moment','Sales')
% l(2)=legend(h(2),'LegendForSecondFigure')

%%
x1 =0:.01:10; y1 = sin(x1);
x2 =0:.01:10; y2 = cos(x1);

figure
plot(x1,y1,'k',x1,tan(y1),'r','linewidth',2),xlabel('time'),ylabel('Force'),legend('myplot1','myplot2')

figure
plot(x2,y2,x2,acos(y2),'linewidth',2),xlabel('time'),ylabel('Energy'),legend('myplot3','myplot4')