필터 지우기
필터 지우기

how to delete duplicate values in a cell array of characters

조회 수: 1 (최근 30일)
cat cat
cat cat 2016년 2월 9일
댓글: Julian Hapke 2016년 2월 10일
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

채택된 답변

Julian Hapke
Julian Hapke 2016년 2월 9일
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
Guillaume
Guillaume 2016년 2월 9일
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 2016년 2월 10일
you're right, that's the cleaner way. I often have trouble getting the cell array syntax right...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by