How to find and combine identical numeric arrays within cell arrays?

1 回表示 (過去 30 日間)
Jonathan Cheng
Jonathan Cheng 2016 年 4 月 27 日
回答済み: Jonathan Cheng 2016 年 4 月 27 日
If I have an array with a combination of scalars and different sized vectors within a cell A: A{1} = 10; A{2} = [5 2]; A{3} = [3 9 2]; A{4} = 1; A{5} = [3 9 2]; A{6} = [5 2]; How do I find and merge identical vectors in the order of their first appearance, such that I get: B{1} = 10; B{2} = [5 2]; B{3} = [3 9 2]; B{4} = 1;
I've tried unique and union but it didn't seem to work on numeric arrays. Thanks!

採用された回答

Jonathan Cheng
Jonathan Cheng 2016 年 4 月 27 日
I think I may have found the answer to my own question here, from Mat Fig in the comments section at http://www.mathworks.com/matlabcentral/fileexchange/25917-unique-rows-for-a-cell-array
ii = 1;
while ii<size(A,1)
tf = true(size(A,1),1);
for jj = ii:size(A,1)
if isequal(A(ii,:),A(jj,:)) && ii~=jj
tf(jj) = 0;
end
end
A = A(tf,:);
ii = ii + 1;
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