Insert figure title in multiple plots from a cell array
Ältere Kommentare anzeigen
Hi all, I've a dataset (records from different places) with the site names stored in a cell array, the records are in a matrix where the 1st column is the key code of the site, the 2nd and 3th columns contain the data. Moreover, I've an array of the key codes for each site. For example:
DATA.site_name = {'torino'; 'roma'; 'firenze'; 'napoli'};
DATA.key = (1; 2; 3; 4);
DATA.value = [1 500 16; 1 600 18; 1 700 20; 2 650 17; 2 750 18; 3 850 19; 3 900 20; 3 950 21; 3 1000 22; 4 50 15; 4 70 20];
I would plot multiple figures (i.e. 4 figures), one for each key number and add the site name in the plot title.
1 Kommentar
Adam
am 10 Feb. 2017
If the only aspect you are asking a question about is putting the title in a figure then
doc title
should tell you what you need. Creating a loop and extracting the string from a cell array is not difficult.
Akzeptierte Antwort
Weitere Antworten (2)
KSSV
am 10 Feb. 2017
clc; clear all ;
DATA.site_name = {'torino'; 'roma'; 'firenze'; 'napoli'};
DATA.key = [1; 2; 3; 4] ;
for i = 1:4
subplot(2,2,i)
plot(rand(1,10)) % plot your data
title(DATA.site_name{i})
end
Rik
am 10 Feb. 2017
I personally prefer subplots, so I implemented that, but you can just as easily use figure(n) instead. If you use subplots, you can also add a caption for everything with suptitle.
DATA.site_name = {'torino'; 'roma'; 'firenze'; 'napoli'};
DATA.key = [1; 2; 3; 4];%you wrote () instead of []
DATA.value = [1 500 16; 1 600 18; 1 700 20; 2 650 17; 2 750 18; 3 850 19; 3 900 20; 3 950 21; 3 1000 22; 4 50 15; 4 70 20];
figure(1)
for n=1:length(DATA.key)
key=DATA.key(n);
x=DATA.value(DATA.value(:,1)==key,2);
y=DATA.value(DATA.value(:,1)==key,3);
subplot(2,2,n)%or figure(n), whichever you prefer
plot(x,y)
title(DATA.site_name{n})
end
Kategorien
Mehr zu Cell Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!