MATLAB: Extracting the same column in a cell array for anova

extractgroupMATLABmatrix

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.

Best Answer

'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)