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

4 views (last 30 days)
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

Answers (1)

lokender Rawat
lokender Rawat on 5 Apr 2018
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 Comments
Tiago Dias
Tiago Dias on 5 Apr 2018
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?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!