how to delete duplicate values in a cell array of characters

15 views (last 30 days)
cat cat
cat cat on 9 Feb 2016
Commented: Julian Hapke on 10 Feb 2016
hi! I have this cell array of charachter:
a={'1';'1';'1';'1';'1';'3';'3';'3';'3';'3';'3';'4';'4';'4';'4'};
and I want to trasform it in this:
a={'1';'';'';'';'';'3';'';'';'';'';'';'4';'';'';''};
can you help me? thanks

Accepted Answer

Julian Hapke
Julian Hapke on 9 Feb 2016
a={'1';'1';'1';'1';'1';'3';'3';'3';'3';'3';'3';'4';'4';'4';'4'};
[~,c,~]=unique(a);
tmp=true(size(a));
tmp(c)=false;
[a{tmp}] = deal('')
  3 Comments
Julian Hapke
Julian Hapke on 10 Feb 2016
you're right, that's the cleaner way. I often have trouble getting the cell array syntax right...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!