Seperating data into matrices based on names
Ältere Kommentare anzeigen
Hi,
I have a matrix of raw data stored in data.rawdata. Each row corresponds to a measurement which is labeled and the labels are stored at data.label. Labels could be repeated. So I want to seperate the data into different groups based on labels which I have been doing with the followid code:
data.labels=labels;
data.rawdata=rawdata;
groups=unique(data.labels);
for i=1:length(groups);
measurements{i,:}=data.rawdata((data.labels)==groups(i)),:);
end
I want to use the measurements that are seperated to save tt pp and pr results into seperate cells but brace indexing is not supported for this format inside the brackets...
for i=1:length(groups)
[tt{i,:},pp{i,:},pr{i,:}]=pca(measurements{i,:},10);
end
How can I do the pca calculations on different groups seperately? And how can I store the tt, pp, and pr seperately for different measurement groups?
I could do all this manually but the point is that I want to speed up the calculations by automizing
Another question which is of less importance:
is it possible to save the data in a cell array with different names with a code like: (I know this doesn'T work in the current format'
measurements.gourps(i)=data.rawdata((data.labels)==groups(i)),:);
I am looking forward to answers.
Thanks!
1 Kommentar
Ameer Hamza
am 26 Mär. 2020
For the first part, you can directly use splitapply() instead of for loop to split your matrix; however, for this purpose, your code is also fine.
Now the error is actually caused by the left-hand side of
[tt{i,:},pp{i,:},pr{i,:}]=pca(measurements{i,:},10);
Can you make sure that the variables tt, pp, pr are not already defined with some other datatype.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical 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!