% Define anonymous function to implement centre of mass calculations
A=@(x,y)y*x/sum(y)

% Example #1
x = [0 2; 3 4; 0 1; 1 1];
y = [2 6 2 10];
A(x,y)

% Example #2
x = [3 1; 0 0; 1 4];
y = [2 4 1];
A(x,y)