How to make the correlation values appear at a mapcolor?

2 ビュー (過去 30 日間)
Julia Moore
Julia Moore 2020 年 6 月 3 日
回答済み: Jayanti 2024 年 10 月 10 日
I am trying to do the mapcolor of my correlation matrix, is it possible to make the correlations values appear at the mapcolor?
figure;
imagesc(RPEARSONIDHma,[-1 1])
colorbar
set(gca,'YTick', [1:11],'YTickLabel',{'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'})
set(gca,'XTick', [1:11],'XTickLabel',{'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'})
set(gcf,'Colormap',autumn)

回答 (1 件)

Jayanti
Jayanti 2024 年 10 月 10 日
Hi Julia,
You can use the “text” function to display the values of the correlation matrix in mapcolor. This function places text annotations at specified locations on the plot.
To display every value of the correlation matrix at mapcolor, use the "for" loop to iterate over the matrix. Below is the code you can refer to use “text” function.
text(j, i, sprintf('%.2f', RPEARSONIDHma(j, i)), ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle', ...
'Color', 'k');
Here i and j are the number of rows and columns of the correlation matrix “RPEARSONIDHma”. “sprintf” will format the value of correlation matrix to two decimal places. “HorizontalAlignment” and “VerticalAlignment” will display the text value at the center with a black color.
I am also attaching MathWorks documentation on “text” for your reference:

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by