Adding text to a plot without specifying it first as a string

2 ビュー (過去 30 日間)
Amavi Silva
Amavi Silva 2024 年 1 月 10 日
コメント済み: Amavi Silva 2024 年 1 月 10 日
Hello,
I have x and y data from 20 different locations which I have plotted on scatter plots to show their correlation. I have also calculated thee correlation coeffecients of each x-y pair as follows:
R = corr(x,y)
rho = corr(x,y,'type','Spearman')
Next I wanted to add these values (both R and rho) as text on my scatter plots and for that I did the following:
str = {['r = R value'],...
['\rho = rho value']}
text(x,y,str)
However, I would like to know whether there is another way where I can directly call calculated 'R' and 'rho' values to the 'text' function so that I don't have to seperately specify them under 'str'.
Thank you in advance
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 1 月 10 日
Any particular reason why you do not want to store it in a variable?

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

採用された回答

madhan ravi
madhan ravi 2024 年 1 月 10 日
編集済み: madhan ravi 2024 年 1 月 10 日
r = 1:3;
rho = 4:6;
plot(1:10)
x = 1:3:9;
y = x+1;
for k = 1 : numel(x)
text(x(k), y(k), {"r = " + r(k), "\rho = " + rho(k)})
% text(x(k), y(k), {sprintf(['r = %.1f'], r(k)), sprintf(['\rho =
% %.1f'], rho(k))}) for older versions
end
  1 件のコメント
Amavi Silva
Amavi Silva 2024 年 1 月 10 日
Thank you for the super-fast answer. Worked exactly as I wanted it. Thanks again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by