Changing title of a bar plot in a for loop
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
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
채택된 답변
  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
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!