MATLAB: How can I give each subplot a different title

for loopsubplottitle

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.

Best Answer

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.