필터 지우기
필터 지우기

I want to add a text in each of my plot of the PlotMatrix

조회 수: 9 (최근 30일)
Tiago Dias
Tiago Dias 2018년 4월 2일
댓글: Tiago Dias 2018년 4월 5일
Hello, In Figure that I attached I got a PlotMatrix, and I would like to add a text in each of the different plots, and the text that i want to add it is a number that is in a matrix
R = [1 1.5 3.7; -0.564 1 5.6; 0.101 0.105 1] so in plot(1,1) i want to add R(1,1), in plot (1,2) i want to add R(1,2), etc
This is what i got
X = randn(50,3);
[R,P] = corrcoef(X)
[~,ax] = plotmatrix(X);
ax(1,1).YLabel.String = 'X1';
ax(2,1).YLabel.String = 'X2';
ax(3,1).YLabel.String = 'X3';
ax(3,1).XLabel.String = 'X1';
ax(3,2).XLabel.String = 'X2';
ax(3,3).XLabel.String = 'X3';
Thanks for your time

답변 (1개)

lokender Rawat
lokender Rawat 2018년 4월 5일
Since you want the values of R(3x3) matrix row-wise to be displayed on the plot in a column-wise fashion. You need to keep track of the 'chart line' objects(represented by S) and 'histogram' objects(represented by H).
The below code does your job, maximize the output figure to see the desired result:
X = randn(50,3);
[R,P] = corrcoef(X)
[S,ax,BigAx,H,HAx]=plotmatrix(X);
ax(1,1).YLabel.String = 'X1';
ax(2,1).YLabel.String = 'X2';
ax(3,1).YLabel.String = 'X3';
ax(3,1).XLabel.String = 'X1';
ax(3,2).XLabel.String = 'X2';
ax(3,3).XLabel.String = 'X3';
[r,c]=size(R)
k=1;
for j=1:c
for i=1:r
if(i==j)
H(i).DisplayName=num2str(R(i,j));
legend(H(i),'Location','northwest')
else
S(k).DisplayName=num2str(R(i,j))
legend(S(k),'Location','northwest')
end
k=k+1;
end
end
Read more on plotmatrix command from the following link and how you can use 'S' and 'H':
>>[S,AX,BigAx,H,HAx] = plotmatrix(___)
Once you have the S and H objects from the plotmatrix, then you can set the display text for each plot. You can read more on Scatter properties from the below link:
Use 'legend' function to align the text to your plot and other features. Read more on 'legend' command:
  댓글 수: 2
Tiago Dias
Tiago Dias 2018년 4월 5일
Thanks for your feedback! works fine!
Tiago Dias
Tiago Dias 2018년 4월 5일
Just a quick question, if i wanted to add both R-values and P-values, since they are both 3x3 like the plotmatrix, i would need another loops like the one you mader for R?

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by