figure title in a loop

3 Ansichten (letzte 30 Tage)
Richard
Richard am 10 Jan. 2012
I am producing a subplot inside a for loop with the following:
for i=1:length(fieldnames(Data));
subplot(length(fieldnames(Data)),1,i);
plot(Data.(Name{i}));
end
Next I want one title which lists the fieldnames, something like:
title('Temperature a)fieldname1 b)fieldname2 c)fieldname3')
However, I don't know how to make the fieldname for 'Data' to appear in the title command.

Akzeptierte Antwort

Chandra Kurniawan
Chandra Kurniawan am 10 Jan. 2012
names = fieldnames(Data);
for i = 1 : length(names);
subplot(length(names),1,i);
%plot(Data.(Name{i}));
title(names{i});
end
  2 Kommentare
Richard
Richard am 10 Jan. 2012
many thanks. In addition, if I was to produce a normal plot instead i.e. have the three data sets overlying one another, how would I change the title of that one plot to show the names of the 3 datasets as shown above?
Chandra Kurniawan
Chandra Kurniawan am 10 Jan. 2012
str = 'Temperature : ';
for i = 1 : length(names);
str = strcat(str, num2str(i),'] ',names{i});
end
And then use str as title.
Eq : title(str);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Math finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by