Split cell based upon logical value
7 ビュー (過去 30 日間)
古いコメントを表示
I have an n x 5 cell array, the 5th column is a logical (0 or 1).
I want to split this into two separate cells, one for false(0) and one for true (1), preserving the cell structure.
What's the best was of doing this?
0 件のコメント
回答 (1 件)
Kaushik Lakshminarasimhan
2017 年 2 月 15 日
編集済み: Stephen23
2017 年 2 月 15 日
You can treat your cell array like a matrix. So if X is your nx5 cell array,
truecells = X([X{:,5}],1:4);
falsecells = X(~[X{:,5}],1:4);
3 件のコメント
Kaushik Lakshminarasimhan
2017 年 2 月 15 日
Sorry I'm not sure what you mean by "won't do anything". That line of code basically splits your original cell array into two cell arrays based on whether the 5th column was true or false.
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!