|
"Man Garc" wrote in message <itseu4$bob$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I have this matrix:
>
> c= [17 24 1 8 15;
> 23 5 0 0 0;
> 4 6 6 0 0;
> 10 5 19 6 0;
> 11 18 25 2 9];
>
> Any idea about how can I convert to 0 the repeated elements in each row? (For example, the element in position 3, 3).
>
> This does not work: d = unique(c,'rows')
>
> Hint: I do not want to use loops (for, etc) as I want the best performance.
>
> Thanks all.
One way:
[csorted,idx] = sort(c,2);
zidx = logical(diff(csorted,[],2));
csorted(:,2:end) = csorted(:,2:end).*zidx;
idx = bsxfun(@plus,idx',0:size(c,2):numel(c)-1);
c2(idx.') = csorted;
c2 = c2.'
|