how can I give each subplot a different title?

조회 수: 75 (최근 30일)
NA
NA 2020년 6월 7일
댓글: Star Strider 2020년 6월 7일
Hi,
I was wondering if someone could please help me.
I would like to give my subplots the following titles: 0.4mA, 0.6mA, 0.8mA, 1.2mA and 1.6mA
My code is:
figure
for ii=1:5
subplot(5,1,ii);
bar(conRR(2:end,1), conRR(2:end, ii+1));
xticks(1:1:16);
ylim([0 80]);
end
t = sgtitle('Respiratory Rate');
t.FontSize = 13;
t.FontWeight = 'bold';
I'm currently using MATLAB R2019b.
Thanks.

채택된 답변

Star Strider
Star Strider 2020년 6월 7일
Easiest is to use a cell array, then reference it.
Create the titles as:
sbpttl = {'0.4mA', '0.6mA', '0.8mA', '1.2mA', '1.6mA'}; % Subplot Title Cell Array
then:
conRR = [(0:10).' rand(11,5)*80]; % Create Matrix
sbpttl = {'0.4mA', '0.6mA', '0.8mA', '1.2mA', '1.6mA'}; % Subplot Title Cell Array
figure
for ii=1:5
subplot(5,1,ii);
bar(conRR(2:end,1), conRR(2:end, ii+1));
xticks(1:1:16);
ylim([0 80]);
title(sbpttl{ii})
end
t = sgtitle('Respiratory Rate');
t.FontSize = 13;
t.FontWeight = 'bold';
I created ‘conRR’ to test my code, Use your ‘conRR’ matrix for your plots.
  댓글 수: 2
NA
NA 2020년 6월 7일
Thank you ever so much!
Star Strider
Star Strider 2020년 6월 7일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020년 6월 7일
figure
conRR=linspace(1,100,100);
conRR(:,2)=sin(conRR(:,1));
conRR(:,3)=sin(conRR(:,1));
conRR(:,4)=sin(conRR(:,1));
conRR(:,5)=sin(conRR(:,1));
for ii=1:5
subplot(5,1,ii);
bar(conRR(2:end,1), conRR(2:end, ii+1));
xticks(1:1:16);
ylim([0 80]);
title(['Respiratory Rate: ' num2str(ii) ]);
end
  댓글 수: 1
NA
NA 2020년 6월 7일
Thanks for your response. The main title of the subplot would be 'Respiratory Rate'. However, I'm looking to give each subplot a title as follows: 0.4mA, 0.6mA, 0.8mA, 1.2mA and 1.6mA
i.e. 1st subplot title = 0.4mA
2nd subplot title = 0.6mA
3rd subplot title = 0.8mA
etc.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by