Multiple points on plot into one point

조회 수: 7 (최근 30일)
TJ
TJ 2017년 10월 25일
답변: Vaidyanathan Thiagarajan 2017년 11월 2일
I made plots that have 4 data points at each respective x coordinate. I want to take the average of these four points and plot them again at their respective x coordinate (so there is only one point at each x coordinate). This is what I currently have to get the four points and I cannot seem to get the average into one point:
hold
plot(averagesD(1,2),averagesD(1,7),'b^')
plot(averagesD(2,2),averagesD(2,7),'gv')
plot(averagesD(3,2),averagesD(3,7),'r<')
plot(averagesD(4,2),averagesD(4,7),'k>')
ylim([0,1])
title(fnameDeutan)
saveas(gcf,fnameD,'jpg')
close

답변 (1개)

Vaidyanathan Thiagarajan
Vaidyanathan Thiagarajan 2017년 11월 2일
Hi,
It is not clear what you are trying to do here. I am assuming this is what you want :
You have 4 points as follows :
XY = [0 0; 1 0 ; 1 1; 0 1];
To compute the average of these 4 points, you can use the 'mean' function :
C = mean(XY);
In the above example, the XY points define the 4 corners of a unit square and the mean of the 4 points would give you the centroid of the square i.e. (0.5,0.5).
You can use plot/scatter functions to display the square and the centroid as follows :
%Plot the square
plot([XY(:,1);XY(1,1)],[XY(:,2);XY(1,2)]);
hold on;
%display the centroid
scatter(C(1),C(2),'r+')
Hope this helps!
Best Regards,
Vaidyanathan

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by