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