how i can convert a matrix to a adjacency matrix

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by