Unique elements in cell array

unique for numeric cell arrays. If c = {[0],[1,2],[0],[8],[1,2]} returns {[0],[1,2],[8]}
2K download
Aggiornato 8 giu 2011

Visualizza la licenza

function [Au, idx, idx2] = uniquecell(A)

Same as built-in unique, but works for cell arrays where each element is a numeric array.

For A a cell array of matrices (or vectors), returns Au, which contains the unique matrices in A, idx, which contains the indices of the last appearance of each such unique matrix, and idx2, which contains th indices such that Au(idx2) == A

Example usage:

A = {[1,2,3],[0],[2,3,4],[2,3,1],[1,2,3],[0]};
[Au,idx,idx2] = uniquecell(A);

Results in:

idx = [6,5,4,3]
Au = {[0],[1,2,3],[2,3,1],[2,3,4]}
idx2 = [2,1,4,3,2,1]

Algorithm: uses cellfun to translate numeric matrices into strings then calls unique on cell array of strings and reconstructs the initial matrices.

Cita come

Patrick Mineault (2024). Unique elements in cell array (https://www.mathworks.com/matlabcentral/fileexchange/31718-unique-elements-in-cell-array), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2008b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Characters and Strings in Help Center e MATLAB Answers
Riconoscimenti

Ispirato: uniqueCellGeneralized(A), uniqueCells

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.0.0.0