Subplots with titles in the loop

1 次查看(过去 30 天)
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...
  2 个评论
Kevin Chng
Kevin Chng 2018-10-16
i guess you are storing 3 ppl name in the variable name, therefore, try indexing it for each figure.
name(bb)
KDRA
KDRA 2018-10-16
That works! thanks. I actually tried that before but it was overwriting itself...

请先登录,再进行评论。

采纳的回答

Kevin Chng
Kevin Chng 2018-10-16
编辑:Kevin Chng 2018-10-16
Try indexing name for each figure.
name(bb)

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by