Multiple points on plot into one point
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Vaidyanathan Thiagarajan
am 2 Nov. 2017
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!