how i can convert a matrix to a adjacency matrix

5 ビュー (過去 30 日間)
fereshteh izadi
fereshteh izadi 2015 年 12 月 11 日
回答済み: Walter Roberson 2015 年 12 月 11 日
Hello, i have a matrix of which i pasted few rows in the below, i want to convert this matrix to an adjacency matrix. how i can do that please?
TFLocus TargetLocus InteractionType
AT5G10140 AT1G65480 -1
AT5G11260 AT1G27480 -1
AT5G11260 AT5G53370 -1
AT5G11260 AT1G03630 -1
AT5G11260 AT1G13600 -1
AT5G11260 AT2G41670 -1
AT5G11260 AT2G05160 -1
AT5G11260 AT2G40170 -1

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 11 日
fid = fopen('YourFileNameHere.txt', 'rt');
datacell = textscan(fid, '%s%s%d', 'HeaderLines', 1);
fclose(fid);
TFLocus = datacell{1};
TargetLocus = datacell{2};
all_locus = unique([TFLocus; TargetLocus]);
num_locus = length(all_locus);
[~, TFidx] = ismember(TFLocus, all_locus);
[~, Targidx] = ismember(TargetLocus, all_locus);
adj_matrix = accumarray([TFidx(:), Targidx(:)], 1, [num_locus, num_locus]);
Now, location J, K of adj_matrix is >= 1 for the places where all_locus{J} is in the TFLocus column and all_locus{K} is in the TargetLocus column. The value will reflect the number of times that combination appeared.
To find any particular item, LocusName, it is at index
[~, idx] = ismember(LocusName, all_locus);
or equivalently,
idx = find(strcmp(LocusName, all_locus));
Also, the K'th line (excluding the header) becomes the index pair TFidx(K), Targidx(K)

その他の回答 (1 件)

Eng. Fredius Magige
Eng. Fredius Magige 2015 年 12 月 11 日
Adjacency matrix is characterised by its squared indexes (row X column) the same. It seem you have only two character from your first column in which assist you to generate a simple code toward a adjacency matrix (from your third column and thus generate -1/1 and 0, intended values)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by