Center of two points (positive and nenegative values)
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
martin martin
el 21 de Mzo. de 2019
Comentada: martin martin
el 22 de Mzo. de 2019
Hello guys,
could anyone explain to me how to calculate the center of gravity for negative values? This code work only for possitive values, for example if values will be 10 and 10 ( v = [10 10], the centroid is at the middle, of values will be 0 and 10 (v - [0 10]) then centrid is on the green point. But how can I edit this, for negative values? For example for -10 and -10 (v = [-10 -10]) the centroid will be at the middle, for values -10 and 0 (v = [-10 0]) centraid will be on the blue point.
Best regards.
x = [0 1];
y = [1 1];
v = [5 10];
figure(1);clf
plot(x,y)
hold on
scatter(x,y,100,v,'filled')
axis image
axis([x(1)-1 x(2)+1 y(1)-1 y(2)+1])
xc = sum(v.*x)/sum(v);
yc = sum(v.*y)/sum(v);
hold on
scatter(xc,yc)
colorbar
colormap winter
grid on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209713/image.png)
0 comentarios
Respuesta aceptada
the cyclist
el 21 de Mzo. de 2019
I believe your calculation is correct for negative values of v. The problem is that the point may not lie between the two input points, and in fact may lie outside the axis limits you have defined, so you don't see it.
Try setting
v = [10 -6]
and commenting out the line
axis([x(1)-1 x(2)+1 y(1)-1 y(2)+1])
so that you see the default axis.
Más respuestas (0)
Ver también
Categorías
Más información sobre Scatter Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!