summaryrefslogtreecommitdiff
path: root/centerofmass.m
diff options
context:
space:
mode:
Diffstat (limited to 'centerofmass.m')
-rw-r--r--centerofmass.m18
1 files changed, 18 insertions, 0 deletions
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));