extract the information from a matrix with three columns
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Andrei Bobrov
il 15 Set 2016
Modificato: Andrei Bobrov
il 16 Set 2016
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!