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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by