Extracting the same column in a cell array for anova

조회 수: 10 (최근 30일)
Cside
Cside 2019년 10월 24일
댓글: Adam Danz 2019년 10월 24일
Hi, I currently have a 1 x 8 cell (attached) and would like to extract the same column in every double and run an anova1 on them - eg 1st column in the 41 x 6 double, 1st column in the 80 x 6 double .... (total of 8 groups). May I know how I may do so?
Thank you, any help is much appreciated.

채택된 답변

Adam Danz
Adam Danz 2019년 10월 24일
편집: Adam Danz 2019년 10월 24일
'c' is your cell array. The first line extracts the first column from each of the elements of c and stores their values in a single column vector. The second line creates a grouping variable of the same length indicating which of the cell groups the data are from. See anova1 for more options on the 3rd line.
y = cell2mat(cellfun(@(x)x(:,1),c,'UniformOutput',false).');
group = cell2mat(cellfun(@(x,i)ones(size(x,1),1).*i,c,num2cell(1:numel(c)),'UniformOutput',false).');
p = anova1(y,group)
  댓글 수: 2
Cside
Cside 2019년 10월 24일
편집: Cside 2019년 10월 24일
this works! Is there a line I can add to the code so it does the same for the 2nd to 6th columns of every double?
Adam Danz
Adam Danz 2019년 10월 24일
You'd just need to change the first line. Set col to any column number.
col = 1;
y = cell2mat(cellfun(@(x)x(:,col),c,'UniformOutput',false).');
% ^^^
Walter has a similar variable in his answer, too.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 24일
col_to_extract = 1;
the_columns_as_cells = cellfun(@(C) C(:,col_to_extract), YourCellArray, 'uniform', 0);
You cannot, however, combine these into a single something-by-8 numeric array, as the cells have different numbers of rows.

카테고리

Help CenterFile Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by