For Programmers: Free Programming Magazines  


Home > Archive > Matlab > January 2008 > center of gravity of a matrix









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author center of gravity of a matrix
Walter Roberson

2008-01-31, 8:28 pm

In article <fntuiq$n9i$1@fred.mathworks.com>, german <nospam@yahoo.com> wrote:

>How do I calculate the center of gravity of a matrix?


[rc,cc] = ndgrid(1:size(M,1),1:size(M,2));
Mt = sum(M(:));
c1 = sum(M(:) .* rc(:)) / Mt;
c2 = sum(M(:) .* cc(:)) / Mt;

The center of gravity is then at (c1,c2) or at (c2,c1)
(I'll let you figure out which.)

--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
german

2008-01-31, 8:28 pm

hi,
How do I calculate the center of gravity of a matrix?
thanks
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com