indexing - Shift the index of sparse matrix without loop in matlab -
i afraid inquire this, don't know way shift index of sparse matrix without loop
sparse matrix
a = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 initial matrix of indexes , value is: = [3 7 1; 3 4 1; 5 6 1; 5 7 1; 5 4 1 ] uniq_x = [3,5] uniq_y=[4,6,7]
desired output be:
out = [1 3; 1 1; 2 2; 2 3; 2 1]
my initial solution looks this:
for i=1:size(uniq_x ,1) a(a(:,1)==uniq_x(i,1),1)=i; end i=1:size(uniq_y ,1) a(a(:,2)==uniq_y(i,1),2)=i; end
any suggestion? thanks
if understand correctly, desired result need remove columns , rows contain zeros, , apply find
:
[jj ii] = find(a(any(a,2), any(a,1)).'); out = [ii jj];
matlab indexing sparse-matrix shift
No comments:
Post a Comment