フィルターのクリア

Vectorized way to get unique strings of cell sub-arrays

5 ビュー (過去 30 日間)
cbrysch
cbrysch 2016 年 6 月 24 日
回答済み: Guillaume 2016 年 6 月 24 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by