Filter löschen
Filter löschen

Vectorized way to get unique strings of cell sub-arrays

5 Ansichten (letzte 30 Tage)
cbrysch
cbrysch am 24 Jun. 2016
Beantwortet: Guillaume am 24 Jun. 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.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by