Convert correlation matrix into a weighted adjacency matrix

8 ビュー (過去 30 日間)
Dinal Jayasekera
Dinal Jayasekera 2020 年 3 月 16 日
回答済み: Abhiram 2025 年 1 月 31 日
Hi all,
How would I convert an nxn correlation matrix with a mix of positive and negative numbers into a weighted connection matrix? How should I go about converting the negative numbers into positive ones so that I can eventually plot a directed graph?

回答 (1 件)

Abhiram
Abhiram 2025 年 1 月 31 日
Hi Dinal,
I see that you have a correlation matrix and want to convert it to represent a directed graph.
One way to convert the negative values in the given matrix to positive is to apply a custom transformation that maps [-1, 1] to [0, 1]. For example, the following function scales all the values in the correlation matrix linearly to positive numbers:
transformed_matrix = (correlation_matrix + 1) ./ 2;
The transformed matrix can be used as an adjacency matrix for creating a graph using the MATLAB ‘digraph’ function as shown below:
G = digraph(transformed_matrix);
Refer to the documentation of the ‘digraph’ function for more details. https://www.mathworks.com/help/matlab/ref/digraph.html

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by