How do I save multiple PCA results in a cell array? Error: Brace indexing not supported
1 view (last 30 days)
Show older comments
Hi,
I have this raw data set which includes 18 participants. Each participants raw data (21 columns) is saved in a cell. I would like to run a principal component analysis on each cell and then collect each type of output in a new cell array.
So basically I run:
for i = 1:length(file_list);
[coeff{i},score{i},latent{i},tsquared{i},explained{i},mu{i}] = pca(cell2mat(pre_data{i,1})); % convert each cell to a matrix and run the PCA on each cell
end
I would like to save all coeff outputs for each participant in a cell array, each score output for each participant in a cell array, and so on...
This way I would have six new cell arrays with 18 cells each in which I have the PCA outputs for each participant.
But somehow the code above gives me the error:
"Unable to perform assignment because brace indexing is not supported for variables of this type."
How would I solve this?
Thnaks!
0 Comments
Accepted Answer
Star Strider
on 6 May 2022
I am not certain what the problem is.
This runs without error for me, and produces the appropriate result —
LD = load('pre_data.mat');
pre_data = LD.pre_data;
for i = 1:length(pre_data);
[coeff{i},score{i},latent{i},tsquared{i},explained{i},mu{i}] = pca(cell2mat(pre_data{i,1})); % convert each cell to a matrix and run the PCA on each cell
end
The only difference is that this iterates on the length of ‘pre_data’ not ‘file_list’ since I only have the cell arrays.
.
4 Comments
More Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!