how i can convert a matrix to a adjacency matrix
조회 수: 6 (최근 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
댓글 수: 0
채택된 답변
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)
댓글 수: 0
추가 답변 (1개)
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!