How to plot correlation coefficient matrix plot?

388 ビュー (過去 30 日間)
Roja Eliza
Roja Eliza 2022 年 6 月 29 日
編集済み: Adam Danz 2022 年 7 月 1 日
I want to plot a correlation coefficient matrix plot and I want to show the values at each individual box as shown in the picture. I have my my calculated correlation coeff values.

回答 (1 件)

Adam Danz
Adam Danz 2022 年 6 月 29 日
編集済み: Adam Danz 2022 年 6 月 29 日
Assuming you already have the correlation matrix, use heatmap. The upper triangle can be filled with NaNs.
S = load('Data_Canada');
r = corr(S.Data)
r = 5×5
1.0000 0.9266 0.7401 0.7287 0.7136 0.9266 1.0000 0.5908 0.5716 0.5556 0.7401 0.5908 1.0000 0.9758 0.9384 0.7287 0.5716 0.9758 1.0000 0.9861 0.7136 0.5556 0.9384 0.9861 1.0000
% Replace upper triangle with NaNs
isupper = logical(triu(ones(size(r)),1));
r(isupper) = NaN
r = 5×5
1.0000 NaN NaN NaN NaN 0.9266 1.0000 NaN NaN NaN 0.7401 0.5908 1.0000 NaN NaN 0.7287 0.5716 0.9758 1.0000 NaN 0.7136 0.5556 0.9384 0.9861 1.0000
% Plot results
h = heatmap(r,'MissingDataColor','w');
labels = ["wt","hp","xy","ad","tt"];
h.XDisplayLabels = labels;
h.YDisplayLabels = labels;
  2 件のコメント
Roja Eliza
Roja Eliza 2022 年 6 月 30 日
Thanks a lot..works fine. just one query I want to reverse the colour from depper shade to lighter which I cannt seem to edit in the property inspector. It only takes pre defined colour schemes
Adam Danz
Adam Danz 2022 年 6 月 30 日
編集済み: Adam Danz 2022 年 7 月 1 日
Flip the colormap using flipud
h.Colormap = flipud(h.Colormap);
where h is the heatmap object.

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

カテゴリ

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