detecting TRUE elements of a cell array

4 次查看(过去 30 天)
I have a 12x3 cell array of logical vectors, as shown below:
[true; false] [false; false] [false; true]
[true; false] [false; true] [false; false]
true false false
false false true
true false false
true false false
[true; false] [false; false] [false; true]
true false false
[true; false] [false; false] [false; true]
true false false
[false; false] [true; false] [false; true]
[true; false] [false; true] [false; false]
I'd like to end up with two 12x3 matrices. The first matrix would be composed of 1 if all cell elements are TRUE or 0 otherwise for each element. The second matrix would consist of 1 if any cell elemnts are TRUE, 0 otherwise. For example, my the first six rows of the first matrix would look like this:
0 0 0
0 0 0
1 0 0
0 0 1
1 0 0
1 0 0
while the first six rows of the second matrix would look like this:
1 0 1
1 1 0
1 0 0
0 0 1
1 0 0
1 0 0

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-12-12
编辑:Azzi Abdelmalek 2012-12-12
y={[true; false] false; false] [false; true]
[true; false] false; true] [false; false]
true false false
false false true}
out1= cellfun(@(x) all(x),y)
out2= cellfun(@(x) any(x),y)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by