matlab - Finding indexes, intersection and then ranking in a matrix? -
i have matrix follows:
a = [1 0 0 0 0 0 0; 1 1 0 0 0 0 0; 1 0 1 0 0 0 0; 1 1 0 1 1 0 0; 1 1 0 1 1 0 0; 1 0 1 0 0 1 1; 1 0 1 0 0 1 1]
of wish create following table:
x - each rows index of cols having 1 y - each cols index of rows having 1 z - intersection set s.no x y z rank(comparing x & z) 1 1 1,2,3,4,5,6,7 1 2 1,2 2,4,5 2 ii 3 1,3 3,6,7 3 ii 4 1,2,4,5 4,5 4,5 iii 5 1,2,4,5 4,5 4,5 iii 6 1,3,6,7 6,7 6,7 iii 7 1,3,6,7 6,7 6,7 iii
of above table, x , y columns have been found of matlab code provided sir luis mendo previous question. code follows:
[ii jj] = find(a); %// find row , col indices (ii , jj respectively) rows = accumarray(ii,jj,[], @(v) {sort(v).'}); %'// group jj per ii, , sort cols = accumarray(jj,ii,[], @(v) {sort(v).'}); %'// group ii per jj, , sort rows{:} cols{:}
now wish find intersection set i.e. z m not able find using intersection command.
further ranking done on comparing columns x , z in such manner minimum of elements in both columns, maximum of common elements should there , each time common element should emitted whole x column further comparison again minimum of elements in both sets max common elements can found.
please help.
for intersection, work a & a.'
:
[ii jj] = find(a & a.'); z = accumarray(ii,jj,[], @(v) {sort(v).'});
Comments
Post a Comment