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

1 visualización (últimos 30 días)
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!

Respuesta aceptada

Jonathan Cheng
Jonathan Cheng el 27 de Abr. de 2016
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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by