-5

How can I calculate the mean of a group of rows and put the in a matrix such as:

1  4   5
1  34  4
1  65  0
1  5   3
2  3   44
2  52  4
2  5   6
3  9   2
3  9   1
3  9   9

So I can have a matrix as

1  27 4 
2  20 18
3  9  4

Thx

OOzy Pal
  • 1
  • 3

1 Answers1

0

Assuming original data is in matrix A:

indx=unique(A(:,1));
for ii=1:numel(indx)
  RowMean(ii,:)=mean(A(1,:)==indx(ii),:);
end
Floris
  • 45,857
  • 6
  • 70
  • 122
  • 2
    You can avoid the for loop by using the `accumarray` function, as [shown here](http://stackoverflow.com/questions/16086874#16087358)... – Eitan T May 12 '13 at 17:30
  • @eitan you are right . This is "a" way, not the "best" way. Thanks for the link. – Floris May 12 '13 at 17:33