how i can convert a matrix to a adjacency matrix

2 次查看(过去 30 天)
hi, i have below matrix
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
using the below code from one of member of this website i converted my matrix to an adjacency matrix but the resulted matrix was without column name or rowname while i need these gene IDs as column name and row name in a symmetric matrix then writing the result in a txt file, may some please complete this code for me??? my needed matrix must contain values 0 or 1 please help me kindly thank you the used code 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]);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by