How do I save multiple PCA results in a cell array? Error: Brace indexing not supported
조회 수: 2 (최근 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!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!