Newbie to Matlab: How to find duplicates within a cell of arrays, arrays have varying sizes
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have a 100 x 1 cell containing arrays of varying length from 5 to 8. Here's an example:
A = [1x7 double] [1x6 double] [1x6 double] [1x7 double] [1x5 double]
Each of these arrays looks something like [1 5 20 12 25 27 1]. Is there a fast way to identify any duplicates within the entire cell and delete them so you're left with only unique arrays? I've been searching on this site but can't seem to find a way to deal with varying length arrays.
Thank you so much for your help!
Newbie to Matlab
0 comentarios
Respuesta aceptada
Teja Muppirala
el 15 de Nov. de 2011
Here is a one rather exotic way of doing it:
% Step 1: Convert to strings
Aunique = cellfun(@(x)char(typecast(x,'uint8')), A, 'unif',0);
% Step 2: Call the UNIQUE command
Aunique = unique(Aunique);
% Step 3: Reconvert to doubles
Aunique = cellfun(@(x) typecast(uint8(x),'double'),Aunique,'unif',0)
2 comentarios
Más respuestas (1)
Walter Roberson
el 15 de Nov. de 2011
A( any(triu(bsxfun(@isequal, A, A.'),1)) ) = [];
3 comentarios
Walter Roberson
el 15 de Nov. de 2011
There might be a version difference: the current documentation does indicate that cells are allowed.
You could use
A( any(triu(0+bsxfun(@(J,K) isequal(A{J},A{K}), (1:length(A)).', 1:length(A)),1)) ) = [];
Ver también
Categorías
Más información sobre Numeric Types 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!