How do I plot a cell array where every cell contains an (x,2) matrix?
Afficher commentaires plus anciens
I am collecting large amounts of data that are output as .dat files. I filter through my entire directory to choose all the .dat files and then reassign them into a cell array as I go. The data imports as a structure when imported using importdata().
My code:
dr = dir('my directory');
c = 1;
for i = 1 : length(dr) % Sort through directory
fln = dr(lc).name; % get filename
[pathstr, name, ext] = fileparts(fln); % get filename parts
if strcmpi(ext,'.dat') % If file is .mat
x = importdata(fln); % Load file - currently a struct
RawData{c,1} = name; % Move file name into Col 1, Row 'c'
RawData{c,2} = x.data; % Move data (n by 2) into Col 2, Row 'c'
c = c + 1; % Increase counter
end
end
I have a cell array:
RawData =
'a14' [1603x2 double]
'a15' [1574x2 double]
'a16' [1632x2 double]
'a21' [1602x2 double]
'a22' [1635x2 double]
'a23' [1603x2 double]
'a24' [1640x2 double]
'a31' [1631x2 double]
'a32' [1605x2 double]
'a33' [1607x2 double]
'a34' [1605x2 double]
'a35' [1569x2 double]
How do I plot each of these (column 1 vs. column 2) all on the same plot without a loop? I want them to be different colors so that I can label them individually in the legend. I am also able to separate the data so that all 'x' data is in column 3 and all 'y' data is in column four so I would have an (n x 3) cell array.
Thanks.
Réponse acceptée
Plus de réponses (1)
Khalid
le 24 Avr 2014
0 votes
grades_imp = importdata('filename.dat');
A=grades_imp.data; B=grades_imp.textdata; C=cell2mat(B(2:end, 1)); time_hours = (mod(datenum(C), 1)) * 24; % transform hh:mm:ss to hours rel1 = A(:,1); rel2 = A(:,2); rel3 = A(:,3); rel4 = A(:,4); rel5 = A(:,5); rel6 = A(:,6); plot (time_hours,rel1,'b' ,time_hours,rel2,'r', time_hours,rel3,'g',time_hours,rel4,'y' ,time_hours,rel5,'w', time_hours,rel6,'m')
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!