MATLAB: How i can convert a matrix to a adjacency matrix

matrix

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

Best Answer

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)