i am plotting a scatter plot X= [ 2 ,3,4,5] Y=[10,20,30,40] scatter(X,Y) i am looking for putting y values on the scatter plot...any specific code or hint can anyone help.i am using 2016b version.Thank you in advance.

1 件のコメント

Voss
Voss 2022 年 1 月 17 日
Well, the code - as you have it now - works:
X= [ 2 ,3,4,5]
X = 1×4
2 3 4 5
Y=[10,20,30,40]
Y = 1×4
10 20 30 40
scatter(X,Y)

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

 採用された回答

Voss
Voss 2022 年 1 月 17 日

0 投票

You need to convert those cell arrays to numeric matrices before you can plot them (scatter or otherwise):
X= { 2 ,3,4,5}
X = 1×4 cell array
{[2]} {[3]} {[4]} {[5]}
Y={ 10,20,30,40}
Y = 1×4 cell array
{[10]} {[20]} {[30]} {[40]}
scatter(cell2mat(X),cell2mat(Y))

3 件のコメント

Prasad Joshi
Prasad Joshi 2022 年 1 月 17 日
Thank you for the answer Benjamin.if i want Y data on that scatter plot any specific text can you suggest for example At (3,20) it should show as data on scatter like (3,20) on plot or simply 20 that will also work
Voss
Voss 2022 年 1 月 17 日
編集済み: Voss 2022 年 1 月 17 日
You can use text() or annotation() or maybe datatip() for that, sounds like. Here it is with text():
X= [ 2 ,3,4,5];
Y=[10,20,30,40];
scatter(X,Y);
text(X(2),Y(2),sprintf(' (%d,%d)',X(2),Y(2)));
Prasad Joshi
Prasad Joshi 2022 年 1 月 18 日
Thank you Benjamin it worked

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

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 1 月 17 日
編集済み: Cris LaPierre 2022 年 1 月 17 日

1 投票

Use square brackets to define vectors, not curly braces. You might find MATLAB Onramp helpful, especially chapters 2, 4 & 9. Also, capitalization matters in MATLAB. X is not the same variable as x.
X= [2,3,4,5];
Y=[10,20,30,40];
scatter(X,Y)

2 件のコメント

Prasad Joshi
Prasad Joshi 2022 年 1 月 17 日
Thank you for the answer Cris.if i want Y data on that scatter plot any specific text can you suggest for example At (3,20) it should show as data on scatter plot
Cris LaPierre
Cris LaPierre 2022 年 1 月 17 日

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

カテゴリ

質問済み:

2022 年 1 月 17 日

コメント済み:

2022 年 1 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by