How to remove the duplicate in the cell array but still keep the array structure?

1 回表示 (過去 30 日間)
Hang Vu
Hang Vu 2019 年 5 月 14 日
コメント済み: Hang Vu 2019 年 5 月 16 日
A={[3 11];[6 5 8];[ 11 5];[5]};
I wonder if there is any way to remove the duplicate numbers in A but still keep the dimension of the cell array? like
A={[3 11];[6 5 8];[];[]};
appreciate your time!
  3 件のコメント
Hang Vu
Hang Vu 2019 年 5 月 15 日
Yes, that is my question! i want to keep the structure
Jan
Jan 2019 年 5 月 15 日
@Hang Vu: You forgot to explain, which operation you want to apply. Why does "remove the duplicate in the cell array" produce the output for the shown input? Let me guess:
If a number occurs in an element of the cell, remove it from all subsequent elements.

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 5 月 15 日
編集済み: Jan 2019 年 5 月 15 日
A = {[3 11];[6 5 8];[ 11 5];[5]};
for iA = 1:numel(A)
a = A{iA};
for jA = iA + 1:numel(A)
A{jA} = A{jA}(~ismember(A{jA}, a));
end
end
Or:
list = A{1};
for iA = 2:numel(A)
A{iA} = A{iA}(~ismember(A{iA}, list));
list = union(list, A{iA})
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by