how i can have an adjacency matrix only contains 0 and 1

2 ビュー (過去 30 日間)
fereshteh izadi
fereshteh izadi 2016 年 1 月 9 日
コメント済み: fereshteh izadi 2016 年 1 月 11 日
hello
i have a data frame, i convert that to an adjacency matrix but the adjacency matrix contains 2 while i need only 1 and 0..how i can have an adjacency matrix only contains 1 and 0 please?
this is my data frame
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
by this code i have an adjacency matrix contains 0 and 1 and 2 ..
fid = fopen('Ara_GoldST.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(:)], datacell{3}, [num_locus, num_locus]);
csvwrite('myfile.txt', adj_matrix);
%max(adj_matrix)
%min(adj_matrix)
thank you
  4 件のコメント
Andrei Bobrov
Andrei Bobrov 2016 年 1 月 9 日
Where your attachment file?
fereshteh izadi
fereshteh izadi 2016 年 1 月 11 日
sorry i attached my file now

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 9 日
adj_matrix = adj_matrix > 0;
  2 件のコメント
Guillaume
Guillaume 2016 年 1 月 10 日
Alternatively, you could rewrite the accumarray call to:
adj_matrix = accumarray([TFidx(:), Targidx(:)], 1, [num_locus, num_locus], @(~) 1);
Or to:
adj_matrix = accumarray([TFidx(:), Targidx(:)], 1, [num_locus, num_locus], @prod);
fereshteh izadi
fereshteh izadi 2016 年 1 月 11 日
thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge 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