fork download
  1. % Define anonymous function to implement centre of mass calculations
  2. A=@(x,y)y*x/sum(y)
  3.  
  4. % Example #1
  5. x = [0 2; 3 4; 0 1; 1 1];
  6. y = [2 6 2 10];
  7. A(x,y)
  8.  
  9. % Example #2
  10. x = [3 1; 0 0; 1 4];
  11. y = [2 4 1];
  12. A(x,y)
Success #stdin #stdout 0.44s 121792KB
stdin
Standard input is empty
stdout
A =

@(x, y) y * x / sum (y)

ans =

   1.4000   2.0000

ans =

   1.00000   0.85714