Azzera filtri
Azzera filtri

Vectorized way to get unique strings of cell sub-arrays

5 visualizzazioni (ultimi 30 giorni)
I have an nx12 cell array where the first column itself is a 1x2 cell array containing a string. I was wondering, if there is a vectorized way to get the unique strings from each second column of my sub-array.
Either
unique(MyData{:,1}{1,2})
nor
cellfun(@unique,MyData{:,1}{1,2})
did work as it gives me the error 'Bad cell reference operation.'! I could use a loop to reorganize my data but I think there is a more easier approach to this which I just don't see right now.

Risposta accettata

Guillaume
Guillaume il 24 Giu 2016
If all the cell arrays in the first column are indeed all the same size, you can concatenate them into a single cell array, which is then easy to index:
firstcolumn = vertcat(MyData{:, 1});
unique(firstcolumn(:, 2))

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by