how to Number the data points in the scatter plot – in increasing order of X
125 views (last 30 days)
Show older comments
like this . how to get this plot (need to know how to write the matlab code)
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
0 Comments
Accepted Answer
Alan Stevens
on 21 Apr 2021
Here's one way:
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
[x, I] = sort(x);
y = y(I);
figure
plot([0 100 100 0 0],[0 0 200 200 0],'k'), grid
hold on
for n = 1:numel(x)
text(x(n),y(n),num2str(n))
end
xlabel('x'), ylabel('y')
title('Scatter plot')
2 Comments
Steven Lord
on 21 Apr 2021
There's no need to loop in this scenario.
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
[x, I] = sort(x);
y = y(I);
text(x, y, string(1:numel(x)));
axis([min(x), max(x), min(y), max(y)])
More Answers (0)
See Also
Categories
Find more on Scatter Plots 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!