remove duplicated rows from a cell array ?

Hi Friends, I have used this piece of code to remove duplicated pairs of rows from a cell array but it produces an error. Could anyone help me to fix it?
cell={' A',' B'; ' C',' D' ;'E','F'; ' B',' A'; ' C',' D'}
Desired_output={'A','B';'C','D';'E','F'}
I update the cell to make it more easy to understand.

답변 (2개)

dpb
dpb 2017년 5월 21일

0 개 추천

Sans the orientation (and not sure you can ensure the data are all symmetric to keep the square array?)
>> [u,ix,ib]=unique(c);
>> [n,idx]=histc(ib,1:length(u));
>> c(ix(n==1))
ans =
'BRCA1'
'ESF'
'NBR1'
'TTN'
>>
NB: Do NOT use 'cell' as variable name; that aliases the builtin cell function which, particularly when you're using cell array specifically could have very bad results. I just use c as a placeholder variable above instead; pick a meaningful but not conflicting name.
Andrei Bobrov
Andrei Bobrov 2017년 5월 21일
편집: Andrei Bobrov 2017년 5월 21일

0 개 추천

cell1 = {'ESF','BRCA1';'ELANE','SLPI';'NBR1','TTN';'SLPI','ELANE'};
[~,~,c] = unique(cell1);
[~,~,c1] = unique(sort(reshape(c,size(cell1)),2),'rows');
m = max(c1);
[n,~,ii] = histcounts(c1,[1:m,m + 1]);
out = cell1(n == 1,:);
add
cell1={'A','B'; 'C',' D' ;'E','F'; 'B','A'; 'C','D'};
[~,c] = unique(cell1);
[~,b] = unique(sort(reshape(c,size(cell1)),2),'rows');
out = cell1(b,:);

댓글 수: 3

chocho
chocho 2017년 5월 21일
thanks for your help!
I have tried your code and get this error:
Error using max
Not enough input arguments.
chocho
chocho 2017년 5월 21일
@Andrei Bobrov I post more easy example to make clear, plz check my question.
Andrei Bobrov
Andrei Bobrov 2017년 5월 21일
I'm fixed my typo

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

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 5월 21일

편집:

2017년 5월 21일

Community Treasure Hunt

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

Start Hunting!