1234567891011121314151617181920 |
- function center_of_mass = center_of_mass(x,y)
- % center_of_mass = get_center_of_mass(x,y)
- % y can be a matrix or a vector.
- if size(x,1)<size(x,2) % number of rows < number of columns
- x = x';% now x is a column vector indicating time
- end
- if size(x,2)>1
- error('x should be a 1-d array indicating time');
- end
- sizey = size(y);
- dim_time_y = find(sizey==size(x,1));% which dimension of y equals to time.
- if dim_time_y ~=2 % time should be the columns dimension
- y = y';
- end
- if size(y,2)~=size(x,1)
- error('x and y should have the same length in time');
- end
- center_of_mass = (y*x)./(y*ones(size(x)));
- end
|