how i can convert a matrix to a adjacency matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
fereshteh izadi
le 11 Déc 2015
Réponse apportée : Walter Roberson
le 11 Déc 2015
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
0 commentaires
Réponse acceptée
Walter Roberson
le 11 Déc 2015
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)
0 commentaires
Plus de réponses (1)
Eng. Fredius Magige
le 11 Déc 2015
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)
0 commentaires
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!