adding annotation(text box) to Scatter plot in matlab?

Hi matlab user, let i have,
x=[1 2 3 4 5 6 7];
y=[1 3 4 6 7 8 9]
scatter(x,y,'*');
r=corr(x.',y.','type','pearson');
A=r;
[rho]=corr(x.',y.','type','spearman');
B=rho;
formatspace='Pearson correlation coefficient r = %d';
str=sprintf(formatspace,A);
annotation('textbox',[.3 .5 .1 .1],'string',str)
After the operation of above code, i get the figure in the attachment. now the problem is how to pass the second text (spearman correlation coefficient rho = %d) to the variable name formatspace. Also i have used %d, which gives me result like (r=9.9124e^-01), how i can get my result like r=0.99124. thanks
thanks

 채택된 답변

the cyclist
the cyclist 2017년 2월 14일
편집: the cyclist 2017년 2월 14일

0 개 추천

You can use the text command to place text at any (x,y) coordinate you want.
To display values that are stored in variables, you may need to convert them to strings, for example using the sprintf command.

댓글 수: 4

@ the cyclist and @Adam,thanks for your comments but my problem is not solved. kindly check my edited question and give me some suggestion.thanks
@ the cyclist and @Adam, by using the suggestions of both of you, i get the simple code which has almost solved my problem. If possible then please check my edited question and give me suggestion for the remaining part of my question. thanks
Use this instead
formatspace='Pearson correlation coefficient r = %9.5f';
sir this works well, also suggest me something for the other part. thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2017년 2월 14일

댓글:

2017년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by