extract the information from a matrix with three columns
1 回表示 (過去 30 日間)
古いコメントを表示
I have a matrix with three columns see the attachment i.e.
E1 E2 W
6 1464 0.36
6 1534 0.27
6 1585 0.27
8 1331 0.332
11 445 0.39
13 844 0.286
14 12 0.126
18 952 0.31
19 2376 0.32
20 394 0.22
20 399 0.22
20 589 0.22
394 8 0.236
399 8 0.236
1187 9 0.350
394 10 0.236
445 11 0.390
14 12 0.126
I used this condition
for k=1:size(y,1)
G(y(k,1),y(k,2))=true;
G(y(k,2),y(k,1))=true;
end
B=cellfun(@(x1) find(x1),num2cell(G,2),'un',0);
to extract links information like this:
1 394
2 2378
3 282
4 282
5 536
6 [1464,1534,1585]
7 2087
8 [394,399,1331]
9 1187
I need a third column contains the weight
e.i. {6,[1464,1534,1585],[0.36;0.27;0.27]}
I tried to use the above condition but I did not get the right values. Does anyone have idea how to do that ??
0 件のコメント
採用された回答
Andrei Bobrov
2016 年 9 月 15 日
編集済み: Andrei Bobrov
2016 年 9 月 16 日
EDIT
load('y.mat');
[yy,i0] = unique([y(:,1:2);y(:,[2 1])],'rows');
y3 = repmat(y(:,3),2,1);
y3 = y3(i0);
[a,~,c] = unique(yy(:,1));
[ii,jj] = ndgrid( c,1:2);
B = [num2cell(a), accumarray([ii(:),jj(:)],[yy(:,2);y3],[],@(x){x})];
3 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!