detecting TRUE elements of a cell array

10 ビュー (過去 30 日間)
Andrew
Andrew 2012 年 12 月 12 日
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)
  1 件のコメント
Andrew
Andrew 2012 年 12 月 12 日
Thanks! This worked.

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by