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

1 次查看(过去 30 天)
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!

采纳的回答

Star Strider
Star Strider 2022-5-6
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 个评论
lil brain
lil brain 2022-5-6
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by