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 CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by