Changing title of a bar plot in a for loop

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Thomas
Thomas il 27 Gen 2016
Thank you that sorted it right out.
Star Strider
Star Strider il 27 Gen 2016
If my Answer solved your problem, please Accept it!

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 27 Gen 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.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by