calculating the center of mass

14 views (last 30 days)
Casio
Casio on 8 Nov 2016
Commented: Walter Roberson on 11 Nov 2016
Hi everyone,
I got different datasets, now I wanted to calculate the center of mass the different datasets.
close all, clc
load('dataset1.mat');
plot(x,y, '-'), hold on
load('dataset2.mat');
plot(x,y, '-'), hold on
So I can interpolerate those datasets by just using a "-" inside my plot function but I have no idea how to write a center of mass code, my programming skills in Matlab are quite bad since I programmed for years only with c+, I also tried to find a proper decent code to calculate a center of mass of a 2D-dataset but I just found a thread about a 3D-array....

Answers (2)

Walter Roberson
Walter Roberson on 8 Nov 2016
As usual, the center of mass of something of uniform density is at the centroid.
For finite approximating points pretty much evenly distributed, the centroid is at the mean.

Image Analyst
Image Analyst on 8 Nov 2016
If you want, you can use poly2mask() to create an image and then use regionprops() to compute the centroid and weightedcentroid.
  20 Comments
Image Analyst
Image Analyst on 11 Nov 2016
Maybe your xupper and xlower are swapped.
Walter Roberson
Walter Roberson on 11 Nov 2016
Your
h=(b-a)/n;
should have an abs(). Otherwise in your formula the sign of the area changes depending on whether the points were presented in one direction or the other.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!