Combining multiple figures using for loop

3 views (last 30 days)
Tomer on 22 Oct 2019
Edited: Tomer on 22 Oct 2019
Hi. This question is an extension of the following question.
I am trying to write a MATLAB program using for loop. I have modified the code in the above link a bit.
test_1 is a combined figure of test1_1,test2_1 and test3_1.
test_2 is a combined figure of test1_2,test2_2 and test3_2. etc
I have tried this program but, it doesn't work. It gives
for p=10:10:200
i
% Initial parameters
Dir = 'D:\Test\';
prefix1='test1_vv_10';
prefix2='test2_vv_10';
prefix3='test3_vv_10';
BinSuffix={'p'};
for j = 1:1:length(BinSuffix)
h1(j) = openfig([Dir prefix1 BinSuffix{j} '.fig'],'reuse');
ax1(j) = gca;
end
for j = 1:1:length(BinSuffix)
h2(j) = openfig([Dir prefix2 BinSuffix{j} '.fig'],'reuse');
ax2(j) = gca;
end
for j = 1:1:length(BinSuffix)
h3(j) = openfig([Dir prefix3 BinSuffix{j} '.fig'],'reuse');
ax3(j) = gca;
end
% Combine figures
for j = 1:1:length(BinSuffix)
hf = figure(20);
hold on;
fig1 = get(ax1(j),'children');
fig2 = get(ax2(j),'children');
fig3 = get(ax3(j),'children');
s = gca;
copyobj(fig1,s);
copyobj(fig2,s);
copyobj(fig3,s);
SaveName=['test_vv_p' num2str(j)];
end
savefig('test_vv_p');
end