Name points on a plot based on their order

10 ビュー (過去 30 日間)
Lama Hamadeh
Lama Hamadeh 2022 年 11 月 28 日
コメント済み: Lama Hamadeh 2022 年 11 月 29 日
Hi,
I have the follwoing points:
%define points
ri = [0.3 0.1 ;
0.7 0.1 ;
0.5 0.3 ;
0.1 0.3 ;
0.1 0.7 ;
0.3 0.5 ;
0.5 0.7 ;
0.3 0.9 ;
0.7 0.9 ;
0.9 0.3 ;
0.9 0.7 ;
0.7 0.5];
%visualise points
plot(ri(:,1),ri(:,2),'rx','LineWidth', 1,'MarkerSize', 12)
xlabel('$r_x$','interpreter','latex')
ylabel('$r_y$','interpreter','latex')
xlim([0 1])
ylim([0 1])
set(gca,'TickLabelInterpreter','latex','FontSize',11)
axis square
grid on
The result of the previous plotting will be as shown on the left. However, I would like to add the number of the point right next to it on the plot based on its order in the vector, as shown on the right.
Any help would be appreciated.

採用された回答

Jonas
Jonas 2022 年 11 月 28 日
編集済み: Jonas 2022 年 11 月 28 日
you could add the line
text(ri(:,1),ri(:,2)+0.05,cellstr(num2str((1:size(ri,1))')))
or
text(ri(:,1),ri(:,2)+0.05,strsplit(num2str(1:size(ri,1))))
  2 件のコメント
Jonas
Jonas 2022 年 11 月 29 日
for visual information ;-)
%define points
ri = [0.3 0.1 ;
0.7 0.1 ;
0.5 0.3 ;
0.1 0.3 ;
0.1 0.7 ;
0.3 0.5 ;
0.5 0.7 ;
0.3 0.9 ;
0.7 0.9 ;
0.9 0.3 ;
0.9 0.7 ;
0.7 0.5];
%visualise points
plot(ri(:,1),ri(:,2),'rx','LineWidth', 1,'MarkerSize', 12)
xlabel('$r_x$','interpreter','latex')
ylabel('$r_y$','interpreter','latex')
xlim([0 1])
ylim([0 1])
set(gca,'TickLabelInterpreter','latex','FontSize',11)
axis square
grid on
text(ri(:,1),ri(:,2)+0.05,strsplit(num2str(1:size(ri,1))))
Lama Hamadeh
Lama Hamadeh 2022 年 11 月 29 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by