Changing title of a bar plot in a for loop
1 view (last 30 days)
Show older comments
Hi, I have several sets of data that span over 12 months and have plotted over 12 figures (one for each month), I now want to display the figure with the month as the title but for some reason the figures all display the last month ('Dec') on every figure. Here is the code I am using,
month_string = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
for i = 1:12;
Data_Display = figure();
bar(maxs(i,:),'r');
hold on
bar(mins(i,:),'g');
hold off
ax = gca;
ax.XTick = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
ax.XTickLabel = {'0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23'};
ax.XLabel.String = 'Time';
ax.YLabel.String = 'kW';
for j = 1:length(month_string);
title(month_string{j,1});
end
axis([0 inf 0 1800]);
end
if anyone could point out why it is only displaying the last month for each figure title that would be a great help. Thanks.
2 Comments
Accepted Answer
Star Strider
on 27 Jan 2016
I can’t run your code so I can’t check this.
You may want to eliminate the inner loop:
for j = 1:length(month_string);
title(month_string{j,1});
end
and instead just go with:
title(month_string{i});
See if that does what you want.
1 Comment
More Answers (0)
See Also
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!