## How to delete the duplicate number or using unique in the cell?

Hang Vu

### Hang Vu (view profile)

さんによって質問されました 2019 年 5 月 14 日

### Hang Vu (view profile)

さんによって コメントされました 2019 年 5 月 14 日
Andrei Bobrov

### Andrei Bobrov (view profile)

さんの 回答が採用されました
Let's see if I have A:
A={[3];[6 8 3];[5];[10 5]}
I am trying to delete the duplicate numbers and found that 'unique' can return the array without the duplication.
Is there any way that I can use unique or delete the duplicate to my cell structure? result like this for example:
A={[3];[6 8];[5];[10]}

#### 0 件のコメント

サインイン to comment.

## 1 件の回答

### Andrei Bobrov (view profile)

2019 年 5 月 14 日
採用された回答

A={[3];[6 8 3];[5];[10 5]};
k = repelem((1:numel(A))',cellfun(@numel,A));
B = cell2mat(cellfun(@(x)x(:),A,'un',0));
[a,b] = unique(B,'stable');
out = accumarray(k(b),a,[],@(x){x(:)'});

Hang Vu

### Hang Vu (view profile)

2019 年 5 月 14 日
Thank you! it's perfect.^^
Hang Vu

### Hang Vu (view profile)

2019 年 5 月 14 日
It has a problem:
A={[3];[6 8];[5 10];[10]};
k = repelem((1:numel(A))',cellfun(@numel,A));
B = cell2mat(cellfun(@(x)x(:),A,'un',0));
[a,b] = unique(B,'stable');
A= accumarray(k(b),a,[],@(x){x(:)'})
A{:}
it may return 3x1 cell array in this case.
A =
3×1 cell array
{[ 3]}
{1×2 double}
{1×2 double}
ans =
3
ans =
6 8
ans =
5 10
Could you please help to return the last cell with [] , mean A still has 4x1 cell array
A={[3];[6 8];[5 10];[]}

サインイン to comment.

Translated by