dpb
Posts:
9,254
Registered:
6/7/07


Re: Average value of rows with certain columns
Posted:
Apr 4, 2013 9:57 PM


On 4/4/2013 4:47 PM, Murat wrote: ...
> I have a huge matrix (size 1048766 x 2) and I would like to get average > values of particular rows which have identical column values such as: > > B= > > 2 45 > 3 45 > 4 45 > 5 50 > 3 50 > > desired result: > res= > > 3 45 > 4 50 > ...
Dead ahead...
u=unique(B(:,2)); a=zeros(length(u),2); for i=1:length(u) a(i)=mean(B(B(:,2)==u(i),:)); end
I haven't thought about vectorizing...


