summaryrefslogtreecommitdiff
path: root/centerofmass.m
diff options
context:
space:
mode:
authorMi Zhang <mzhang@email.wm.edu>2012-09-11 16:03:41 -0400
committerMi Zhang <mzhang@email.wm.edu>2012-09-11 16:03:41 -0400
commitd1d7a486cc70665dafe64aaddd44c58e228815b0 (patch)
treeacbf530230d6860c9a85f5f1d67d0e445dde5192 /centerofmass.m
downloadbeam_profiler-d1d7a486cc70665dafe64aaddd44c58e228815b0.tar.gz
beam_profiler-d1d7a486cc70665dafe64aaddd44c58e228815b0.zip
initial commit
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));