How to plot index number of a data in the graph?

25 ビュー (過去 30 日間)
Luan Gloria
Luan Gloria 2019 年 2 月 14 日
コメント済み: Kyle McLaughlin 2022 年 3 月 15 日
Dear MatLab community members,
Let's say I have two vectors, A and B, with ten entries each. B = A*2; Let's say that A=1:1:10;
I want to plot A and B, but instead of ploting circles, crosses etc, I want to plot the index numbers of A and B to show that the content in the position 1 of A is doubled in B. In the picture below I show what I want:
Bild2.jpg
The red dots are the two first entries of vector A, and the blue dots are the two first entries of vector B, however, I cannot correlate these dots among each other (let's say I have a more complicated relationship between A and B, this relation would not be that easily seen). What I want to obtain, is a graph with the vector indexes as in the right side of the graph. Thank you!
  2 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 14 日
N=2;
text(1:N,A(1:N),"A index no"+(1:N))% like this?
text(1:N,B(1:N),"B index no"+(1:N))
Luan Gloria
Luan Gloria 2019 年 2 月 14 日
Dear Ravi, thank you for your reply.
No, I do not want to add a description to a ploted marker. Instead of a marker, I wanna plot a number, which is equivalent to the index of my data point. So, in the pictures below, instead of ploting the circles (or markers as 'o', 'x', '*', etc), I want my markers to be the data point equivalent indexes.
Markers.png
IndexesMarkers.png

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

採用された回答

Mark Sherstan
Mark Sherstan 2019 年 2 月 14 日
The following should get you going in the right direction. If you need more help please post your actual data set.
x = [1 2 3]
y = [4 5 6]
plot(x,y,'.','MarkerEdgeColor','w')
xlim([0 5])
ylim([0 10])
for ii = 1:length(x)
t = text(x(ii),y(ii),num2str(ii));
t.Color = [1 0 0];
end
  2 件のコメント
Luan Gloria
Luan Gloria 2019 年 3 月 26 日
Thank you Mark! That's exactly what I was looking for.
Kyle McLaughlin
Kyle McLaughlin 2022 年 3 月 15 日
Came here looking for exact same thing for purpose of FEM node numbering. Works great thanks!

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by