Hello,
I just leaned MATLAB.
I want to calculate the mean of a matrix by the first column:
Input:
1 9 7 5 72 1 1 1 32 5 5 4 43 1 1 1 33 5 5 4 43 1 1 1 33 5 6 4 44 1 8 1 34 5 5 4 45 1 5 1 36 1 4 1 37 5 5 4 4
Output:
1 9 7 5 72 3 3 2.5 3.53 3 3.25 2.5 3.54 3 6.5 2.5 3.55 5 1 5 16 6 1 4 17 7 5 5 4
My code:
G = findgroups(M(:,1 )); Out = [unique(M(:,1)) splitapply(@mean, M(:,2:end), G)]Error using vertcatDimensions of matrices being concatenated are not consistent.Error in splitapply>localapply (line 257) finalOut{curVar} = vertcat(funOut{:,curVar});Error in splitapply (line 132)varargout = localapply(fun,splitData,gdim,nargout);
Thanks in advance for any suggestions and help!
Yue
Best Answer