Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Average value of rows with certain columns
Replies: 4   Last Post: Apr 5, 2013 5:01 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,181
Registered: 6/7/07
Re: Average value of rows with certain columns
Posted: Apr 4, 2013 9:57 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.