フィルターのクリア

how to plot a correlation matrix between two variables as a heatmap in matlab?

49 ビュー (過去 30 日間)
Anju K Joshi
Anju K Joshi 2019 年 8 月 21 日
コメント済み: Michelle Wagner 2023 年 3 月 4 日
I have two variables which vary with each run of my code. I have to calculate the correlation matrix between these two variables. The matrix axes will be like variable X(first run),variable Y(first run),Variable X(second run),variable Y (second run)......I need to plot this correlation matrix as a heat map?
please help me

採用された回答

Riz
Riz 2019 年 11 月 22 日
Just perform Pearson or Spearman correlation depending on your data. Then display the resulting matrix as an image and apply any colormap of your choice.
%% Code Snippet
corr(yourvariables)
imagesc(ans); % Display correlation matrix as an image
set(gca, 'XTick', 1:sizeofyourcorrmatrix); % center x-axis ticks on bins
set(gca, 'YTick', 1:nsizeofyourcorrmatrix); % center y-axis ticks on bins
set(gca, 'XTickLabel', yourlabelnames); % set x-axis labels
set(gca, 'YTickLabel', yourlabelnames); % set y-axis labels
title('Your Title', 'FontSize', 10); % set title
colormap('jet'); % Choose jet or any other color scheme
colorbar on; %
  3 件のコメント
Martim Zurita
Martim Zurita 2021 年 1 月 22 日
Nilima, write xlabel('Example 1') and ylabel('Example 2') to put names in the x and y axis. See more at https://www.mathworks.com/help/matlab/ref/xlabel.html.
Michelle Wagner
Michelle Wagner 2023 年 3 月 4 日
How do add a scale to this?

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

その他の回答 (1 件)

Niyati Chokshi
Niyati Chokshi 2022 年 5 月 27 日
編集済み: Niyati Chokshi 2022 年 5 月 27 日
I have four variables- 3 of them are caluating the fourth one, thus mismatch of the lengths/dimension. . How do I use imagesc and corr for that?

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by