1

Does anybody know how to solve

removing duplicates - ** only when the duplicates occur in sequence

in Octave? The accepted solution is using diff.

Matlab's diff seems to behave differently than the Octave's one and doesn't accept characters.

Any idea is appreciated.

2
  • 4
    A character can be represented as an int, have you tried typecasting? Commented Jan 21, 2012 at 17:46
  • thanks for the idea... the diff(), it doesn't make any difference whether it's a char or an int... might be an idea. trying Commented Jan 22, 2012 at 11:34

1 Answer 1

1

You can convert the characters to their ASCII codes, then run the solution as given:

a = {'d' 'f' 'a' 'g' 'g' 'w' 'a' 'h'};
aa = cellfun(@(c) c-0, a);             %# convert to ASCII

idx = find(diff(aa) == 0);
a([idx idx+1]) = [];
Sign up to request clarification or add additional context in comments.

3 Comments

that's exactly what I did the day - is somewhat ago now. thanks! =)
@Atmocreations: you're welcome. In the future, you could post a solution to your own problem if you found it.
Thanks, I know about that. But "AlwaysWrong" already gave the answer indirectly...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.