Borrar filtros
Borrar filtros

detecting TRUE elements of a cell array

10 visualizaciones (últimos 30 días)
Andrew
Andrew el 12 de Dic. de 2012
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Dic. de 2012
Editada: Azzi Abdelmalek el 12 de Dic. de 2012
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)

Más respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by