From d1d7a486cc70665dafe64aaddd44c58e228815b0 Mon Sep 17 00:00:00 2001 From: Mi Zhang Date: Tue, 11 Sep 2012 16:03:41 -0400 Subject: initial commit --- centerofmass.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 centerofmass.m (limited to 'centerofmass.m') diff --git a/centerofmass.m b/centerofmass.m new file mode 100644 index 0000000..7050145 --- /dev/null +++ b/centerofmass.m @@ -0,0 +1,18 @@ +% PURPOSE: find c of m of distribution +function [cx,cy,sx,sy] = centerofmass(m); + +[sizey sizex] = size(m); +vx = sum(m); +vy = sum(m'); + +vx = vx.*(vx>0); +vy = vy.*(vy>0); + +x = [1:sizex]; +y = [1:sizey]; + +cx = sum(vx.*x)/sum(vx); +cy = sum(vy.*y)/sum(vy); + +sx = sqrt(sum(vx.*(abs(x-cx).^2))/sum(vx)); +sy = sqrt(sum(vy.*(abs(y-cy).^2))/sum(vy)); -- cgit v1.2.3