Extraction of unique arrays in a cell
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Amir Mahmoudi
el 19 de Sept. de 2024
Editada: Amir Mahmoudi
el 19 de Sept. de 2024
Assume there is a cell of the size 1 by N. Each cell contains an array. Some of the arrays are equal. How can I remove duplicate ones? Is there a "unique" function for cells?
0 comentarios
Respuesta aceptada
Taylor
el 19 de Sept. de 2024
One possible approach:
% Assume 'cellArray' is your 1xN cell array containing arrays
cellArray = {
[1, 2, 3],
[4, 5, 6],
[1, 2, 3], % Duplicate
[7, 8, 9],
[4, 5, 6] % Duplicate
};
% Convert each cell's array to a string representation
arrayStrings = cellfun(@mat2str, cellArray, 'UniformOutput', false);
% Find unique string representations and their indices
[~, uniqueIndices] = unique(arrayStrings, 'stable');
% Use the unique indices to create a cell array without duplicates
uniqueCellArray = cellArray(uniqueIndices);
% Display the result
disp('Cell array with duplicates removed:');
disp(uniqueCellArray);
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell 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!