calculating the center of mass
14 views (last 30 days)
Show older comments
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....
0 Comments
Answers (2)
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
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
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.
See Also
Categories
Find more on Eigenvalue Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
