How can I combine two correlation matrices (corrplot)?

8 ビュー (過去 30 日間)
Agata Nyga
Agata Nyga 2018 年 1 月 19 日
回答済み: Swaraj 2023 年 2 月 10 日
Is there a way to combine upper correlation matrix with lower correlation matrix of two different sets of data? I´ve been trying to figure it out and at this moment can only do it manually, which is not efficient....
  1 件のコメント
Caspar Gevaerts
Caspar Gevaerts 2023 年 2 月 7 日
You can add the upper and lower triangular matrices.
X = rand(5,10);
Y = rand(5,10);
CorrCombined = triu(corr(X),1) + tril(corr(Y))

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

回答 (1 件)

Swaraj
Swaraj 2023 年 2 月 10 日
The corr function is used to calculate the correlation matrix of each dataset, and the triu and tril functions are used to extract the upper and lower triangular matrices, respectively.
Here's an example to clarify this:
X = rand(1,10);
Y = rand(1,10);
R1 = corr(X);
R2 = corr(Y);
% Combine the matrices
CorrCombined = triu(R1,1) + tril(R2);
% Add the diagonal elements of the original correlation matrices
CorrCombined = CorrCombined + diag(diag(R1)) + diag(diag(R2));

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by