I would like to apply a function that is unique to each row of a given matrix, without involving any loops. Suppose I have the following 4-by-5-matrix
full(A) = [0 1 0 0 1 2 1 0 3 0 1 2 0 0 2 0 3 1 0 0]
where A is the corresponding sparse matrix. As an example using a for loop, I can do
uniq = cell(4,1); for i = 1:4 uniq{i} = unique(A(i,:)); end
and I would get the uniq cell structure given
uniq{1} = {1} uniq{2} = {[1 2 3]} uniq{3} = {[1 2]} uniq{4} = {[1 3]}
Is there a faster way to vectorize and avoid loops? I need to apply this to M-by-5 โโmatrices with M large. Note that I am not interested in the number of unique elements in a row (I know there are answers around such a problem).
source share