Split cell based upon logical value
6 次查看(过去 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!