Change or remove duplicate matrix elements
18 views (last 30 days)
I have the matrix:
and I want to add 0.1 to any duplicate entries, so that all values are unique, and none are removed.
I have tried:
But for some reason it has no impact on the matrix..
Your help is greatly appreciated, thanks!
**EDIT: how can i remove all but the first occurance of a duplicate value? unique does not work for me.
More Answers (2)
Fangjun Jiang on 26 Aug 2011
It works in certain degree but your algorith has a flaw. You'll see it clearly running the following.
MaVo on 2 Feb 2016
I had a similar issue with a time sequence in 0.005 s steps, but I figured out a solution that worked for me. My problem during debugging was, that it didn't go into the if-condition. I solved this by comparing integers than double values. Maybe this helps someone.
s_length = length(s_time);
ctr = 1;
for ctr = 2:s_length
% Checking values for debugging
new = uint64(s_time(ctr,1)/0.005);
old = uint64(s_time((ctr-1),1)/0.005);
before = (ctr-1);
if new == old
s_time(ctr:end,1) = s_time(ctr:end,1)+0.005;
if new > (old + 1)
s_time(ctr:end) = s_time(ctr:end) - 0.005;