"any" returns the wrong logical value from a 3D matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I have a 3D matrix (I called it z_wz_b_m), which has a dimension of 225x1x118.
The first element set of this matrix looks as follow:
val(:,:,1) =
0.7610
4.7390
0.6440
4.7390
4.7390
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
4.7390
0.7610
4.7390
0.7610
4.7390
4.7390
0.8469
0.7610
0.7610
0.7610
0.7610
4.7390
0.7610
4.7390
4.7390
4.7390
0.6482
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
4.7390
4.7390
0.7610
4.7390
0.7610
4.7390
4.7390
4.7390
0.7610
0.7610
0.7610
0.7610
0.7610
0.7610
4.7390
0.7610
4.7390
4.7390
4.7390
4.7390
4.7390
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
0.6440
4.7390
4.7390
0.6440
4.7390
4.7390
1.2188
0.7610
4.7390
4.7390
4.7390
0.7610
4.7390
4.7390
0.8067
0.7610
4.7390
4.7390
4.7390
0.8469
0.7610
4.7390
0.7610
4.7390
0.7610
4.7390
4.7390
4.7390
4.7390
0.6482
0.7610
4.7390
0.7610
4.7390
0.7610
4.7390
0.7610
1.3193
4.7390
4.7390
1.1408
0.7610
4.7390
4.7390
4.7390
4.7390
0.7610
0.8724
0.7768
4.7390
0.7768
4.7390
Obviously, it contains values, which are smaller than 0.7. However, when I put
any(z_wz_b_m(:,:,1))<=0.7
it returns 0.
I expect to get 1, since some values are in fact smaller than 0.7.
Could anybody help me to find the error?
2 comentarios
Yazan
el 17 de Ag. de 2021
any returns a binary value (0 or 1), why are you comparing this with 0.7??? Does not make sense! You need to compare the values z_wz_b_m(:,:,1) with 0.7, then use any.
any(z_wz_b_m(:,:,1)<=0.7)
Respuestas (1)
DGM
el 17 de Ag. de 2021
Editada: DGM
el 17 de Ag. de 2021
The input to any() is (implicitly) logical. MATLAB considers nonzero numeric values to be logical true.
In this case, you're testing whether any of the values in your numeric array are nonzero (which is true), and then you're comparing the output (scalar logical true) to see if it's less than or equal to 0.7, which is false.
any(z_wz_b_m(:,:,1))<=0.7
Do this instead.
any(z_wz_b_m(:,:,1)<=0.7)
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!