Asked by Tomer
on 31 Aug 2019

Hello, I am new to MATLAB. I have three MATLAB figures. I want to combine them to compare the data. Can someone help me doing this?

Answer by meghannmarie
on 4 Oct 2019

Accepted Answer

I would save figures then plot them as subplots like this:

%First Figure

h1 = openfig('test1.fig','reuse'); % open figure

ax1 = gca; % get handle to axes of figure

%Second Figure

h2 = openfig('test2.fig','reuse');

ax2 = gca;

h3 = figure; %create new figure

s1 = subplot(1,2,1); %create and get handle to the subplot axes

s2 = subplot(1,2,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);

meghannmarie
on 6 Oct 2019

Do you want them on one axis?

fig = figure();

ax = axes(fig);

hold on

h1 = openfig('test1.fig','reuse');

h2 = openfig('test2.fig','reuse');

h3 = openfig('test3.fig','reuse');

copyobj(h1.Children.Children,ax);

copyobj(h2.Children.Children,ax);

copyobj(h3.Children.Children,ax);

close(h1);

close(h2);

close(h3);

Adam Danz
on 6 Oct 2019

h1 is the figure handle to test1.fig.

h1.Children will list the axes and any other object stored on that figure. If There's just 1 axes and nothing else, you can use this demo code directly. Otherwise you'll need to add an additional step to locate the axis (that's easy - we could help you with that). Then you want to get the children of the axis which will be the handles to any graphic objects stored on the axes. They will then be copied to the new axes.

Tomer
on 15 Oct 2019

Thanks.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## KALYAN ACHARJYA (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_740835

## Tomer (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_740840

## rough93 (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_747380

## prasanth s (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_751914

## SS (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_752794

## Adam Danz (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_752798

## Tomer (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_753043

## Adam Danz (view profile)

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/478355-combine-three-or-more-matlab-figures#comment_753051

Sign in to comment.