Changing title of a bar plot in a for loop

4 ビュー (過去 30 日間)
Thomas
Thomas 2016 年 1 月 27 日
コメント済み: Star Strider 2016 年 1 月 27 日
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 件のコメント
Thomas
Thomas 2016 年 1 月 27 日
Thank you that sorted it right out.
Star Strider
Star Strider 2016 年 1 月 27 日
If my Answer solved your problem, please Accept it!

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 1 月 27 日
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 件のコメント
Star Strider
Star Strider 2016 年 1 月 27 日
If my Answer solved your problem, please Accept it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by