MATLAB: Subplots with titles in the loop

loopsubplottitle

Hi! I am trying to plot two graphs (subplot) for left and right side. I have 10 measurements for each side and the measurements were done for 3 people. My code is:
if true
% code
end
for bb = 1:size(Data.Measured,2)
for kk = 1:size(Data.Name,2)
if strcmpi(Data.Side{kk}, 'Right')
subplot(2,1,1)
Data.legend.sub1{c1} = regexprep(Data.Name{kk},'_',' ');
c1 = c1+1;
legend(Data.legend.sub1)
title([name,' Right'])
else
subplot(2,1,2)
title([name,' Left'])
Data.legend.sub2{c2} = regexprep(Data.Name{kk},'_',' ');
c2 = c2+1;
legend(Data.legend.sub2)
end
semilogx(f_aff, Data.Measured{bb}{kk},'linewidth' ,2 )
hold on
grid on
xlim([200 8000])
xlabel('frequency [Hz]')
ylabel('SPL')
end
figure
end
I am getting almost correct results – three figures with two graphs each with left and right side and all measurements inside. However, the variable 'name' containing initials adds up so I don't have three figures for three different people but I have three figures with all people in each title (see screenshot).
I tried everything and putting 'title' line in different order but it didn't really work…

Best Answer

Try indexing name for each figure.
name(bb)