Vectorized way to get unique strings of cell sub-arrays

5 次查看(过去 30 天)
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.

采纳的回答

Guillaume
Guillaume 2016-6-24
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))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by