how to delete duplicate values in a cell array of characters

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Julian Hapke
Julian Hapke am 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 Kommentare
Guillaume
Guillaume am 9 Feb. 2016
I would have the last line as:
a(tmp) = {''};
I'm sure it involves less work in the background than cell array to comma separated list + deal expansion.
Julian Hapke
Julian Hapke am 10 Feb. 2016
you're right, that's the cleaner way. I often have trouble getting the cell array syntax right...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Math finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by