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})];
更多回答(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!