Merging figures with subplots into a large figure with subplots

Hi all,
I have a question about the merging of figures. I have 5 figures (.fig) consisting of 4 subplots (2x2). I want to merge these figures into one figure with the size of 6x4 where the first original figure will be placed in the left top (6,4,1/6,4,2/6,4,5/6,4,6), the second in the right top (6,4,3/6,4,4/6,4,7/6,4,8) and so on. I tried several things with copyobj and findobj, but did not manage to figure out how to actually merge the subplots.
Can anyone help me with this problem?
Thanks in advance!

Answers (1)

Hi Lars,
I had written this code to extract data from a figure file. Hope few modification will work for you.
clear all;
close all;
clc;
x=0:0.01:3;
for ii=1:4
f(ii)=figure(ii);
for jj=1:4
subplot(2,2,jj),plot(x,x.^jj);
end
end
savefig(f(1),'testFig1');savefig(f(2),'testFig2');
savefig(f(3),'testFig3');savefig(f(4),'testFig4');
clear all;close all;clc
fig(1)=openfig('testFig1.fig');fig(2)=openfig('testFig2.fig');
fig(3)=openfig('testFig3.fig');fig(4)=openfig('testFig4.fig');
kk=1;
for ii=1:4
axObjs = fig(ii).Children;
for jj=1:length(axObjs)
dataObjs = axObjs(jj).Children;
x = dataObjs.XData;
y = dataObjs.YData;
figure(5),subplot(4,4,kk)
if(ishold==0)
hold on;
end
plot(x,y);
kk=kk+1;
end
end

4 Comments

I wrote the code below with your help. But I keep getting this error:
Unrecognized method, property, or field 'XData' for class 'matlab.graphics.GraphicsPlaceholder'.
Error in Merge_figures (line 22)
x=dataObjs.XData;
clear; close all; clc; format compact;
fig(1) = openfig('HR within period.fig');
fig(2) = openfig('TC within period.fig');
kk=1;
for ii=1:2
axObjs=fig(ii).Children;
for jj=1:length(axObjs)
dataObjs=axObjs(jj).Children;
x=dataObjs.XData;
y=dataObjs.YData;
figure(3),subplot(4,4,kk)
if(ishold==0)
hold on;
end
plot(x,y);
kk=kk+1;
end
end
What should I do to make the script work?
dataObjs
dataObjs =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1×301 double]
YData: [1×301 double]
ZData: [1×0 double]
Show
What kind of figure file you do have
is it a line plot or contour plot ? you can check the properties simply typing dataobjs then enter
It is a line plot. DataObjs shows a 0x0 empty GraphicsPlaceholder array, which I do not understand because there is a plot visual in each subplot in the original figure.
You can share your figure file if you whish.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 28 Jun 2021

Commented:

on 29 Jun 2021

Community Treasure Hunt

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

Start Hunting!