필터 지우기
필터 지우기

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)

추가 답변 (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