Question

given

A=1 1   0
1   2   0.563826213141399
1   3   1.18321595677734
1   4   1.95685972913029
2   1   0.563826213141399
2   2   0
2   3   0.830602192143995
2   4   1.65196852337589
2   5   1.77172232586001
3   1   1.18321595677734
3   2   0.830602192143995
3   3   0
3   4   0.821522975656861
3   5   1.12716458303105
3   6   1.78117938413852

as seen row 2 and 5 are same in real but not in the matrix. how can I remove one of the same rows? using unique I couldn't do this.

Était-ce utile?

La solution

It seems like you have a representation of a graph using a weighted adjacency matrix.
If I understand correctly, you wish to have a single entry per edge.

You can do this by taking only the upper triangle of the adjacency matrix

A = sparse( A(:,1), A(:,2), A(:,3), max(A(:,2)), max(A(:,2)) );
[ii jj wij] = find( triu( A ) ) ;
disp( [ii jj wij] )   

outputs:

1 2 0.563826
1 3 1.183216
2 3 0.830602
1 4 1.956860
2 4 1.651969
3 4 0.821523
2 5 1.771722
3 5 1.127165
3 6 1.781179
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top