Creating an adjacency matrix from a table

10 ビュー (過去 30 日間)
William Sheehan
William Sheehan 2019 年 8 月 7 日
回答済み: Steven Lord 2019 年 8 月 12 日
I am trying to create a weighted adjacency matrix that counts the number of times two individuals interact so that I can subsequently create a sparse variable and digraphs.
I have two columns of individual names, each with 182 rows. Each row is indicative of an interaction.
Column 1 contains the individual that distributed the information whereas column 2 contains the name of the individual who recieved the information similar to below:
Screenshot (124).png

回答 (2 件)

Hari Krishna Ravuri
Hari Krishna Ravuri 2019 年 8 月 12 日
You may consider maintaining a lookup table or anything similar, in order to map the sender and receiver with their respective indices in the adjacency matrix. You can get the sender and the receiver by reading each row in the excel file using readtable() and increase the value of the element, corresponding to the sender and the receiver in the adjacency matrix. Please refer to the documentation on readtable() from the following link https://in.mathworks.com/help/matlab/ref/readtable.html.

Steven Lord
Steven Lord 2019 年 8 月 12 日
You can create a digraph by passing in arrays of source node names and target node names. See the sections of the Syntax section on the digraph documentation page that list s and t as inputs.
Read your data into char, string, or cellstr arrays and create the digraph by passing the labels in as s and t. If you need the adjacency matrix, call adjacency on your digraph. Depending on what else you want to do, since your digraph is a multigraph (you have the pairs [A, B] and [C, B] listed twice each in your spreadsheet) you may need or want to call simplify on it first.

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by