how to Number the data points in the scatter plot – in increasing order of X

125 次查看(过去 30 天)
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];

采纳的回答

Alan Stevens
Alan Stevens 2021-4-21
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 个评论
Steven Lord
Steven Lord 2021-4-21
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)])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by