MATLAB: Center of mass and total mass of a matrix

center of masstotal mass

How to calculate a center of mass and total mass of 11×4 matrix?
the matrix is as follows:
a = normrnd(451,131,11,1); b = linspace(-7.67,91.83,11)'; c = linspace(-8.3,8.3,11)'; d = linspace(0,15.21,11)';
A = [a,b,c,d]

Best Answer

tot_mass = sum(A(:));
[ii,jj] = ndgrid(1:size(A,1),1:size(A,2));
R = sum(ii(:).*A(:))/tot_mass;
C = sum(jj(:).*A(:))/tot_mass;
out = [tot_mass,R,C]
Related Question