omit same element inside cell

1 回表示 (過去 30 日間)
NA
NA 2019 年 4 月 3 日
コメント済み: NA 2019 年 4 月 3 日
A={[1,2,3,4],[4,2,3],[1,2,5,6,78,9],[1,2,3,4],[1,2,5,6,78,9],[4,2,3],[5,6,7]};
c=cellfun(@(x) unique(x),A,'UniformOutput',false);
I want to omit same array inside cell
result should be
A={[1,2,3,4],[4,2,3],[1,2,5,6,78,9],[5,6,7]};
  2 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 3 日
?? [4,2,3] & [5,6,7] have the same size there is something wrong in your logic or your explanation
NA
NA 2019 年 4 月 3 日
Sorry I mean same array
[4,2,3] repeated 2 times
[1,2,3,4] repeated 2 times
[1,2,5,6,78,9] repeated 2 times
I want to have them one times

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

採用された回答

Stephen23
Stephen23 2019 年 4 月 3 日
編集済み: Stephen23 2019 年 4 月 3 日
>> A = {[1,2,3,4],[4,2,3],[1,2,5,6,78,9],[1,2,3,4],[1,2,5,6,78,9],[4,2,3],[5,6,7]};
>> N = numel(A);
>> X = false(N,N); % find which arrays are the same:
>> for ii=1:N, for jj=1:ii, X(ii,jj)=isequal(A{ii},A{jj}); end, end
>> Y = X & cumsum(X,1)==1 & cumsum(X,2)==1; % indices that ignore duplicates.
>> Z = A(any(Y,1));
>> Z{:}
ans =
1 2 3 4
ans =
4 2 3
ans =
1 2 5 6 78 9
ans =
5 6 7

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2019 年 4 月 3 日
You can convert the elements of each cell to a char array and apply unique on that cell array of chars.
A = {[1,2,3,4],[4,2,3],[1,2,5,6,78,9],[1,2,3,4],[1,2,5,6,78,9],[4,2,3],[5,6,7]};
% engine
[~,ix] = unique(cellfun(@(x) num2str(x), A ,'un', 0), 'stable') ;
B = A(ix) % as requested
  1 件のコメント
NA
NA 2019 年 4 月 3 日
thanks

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by