Borrar filtros
Borrar filtros

Vectorized way to get unique strings of cell sub-arrays

5 visualizaciones (últimos 30 días)
cbrysch
cbrysch el 24 de Jun. de 2016
Respondida: Guillaume el 24 de Jun. de 2016
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.

Respuesta aceptada

Guillaume
Guillaume el 24 de Jun. de 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))

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by