How do I save multiple PCA results in a cell array? Error: Brace indexing not supported

2 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Star Strider
Star Strider le 6 Mai 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 commentaires
lil brain
lil brain le 6 Mai 2022
Hi @Star Strider I noticed that the issue was gone after I cleared all the variables and ran it again. So its all good now. Thanks for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by