"any" returns the wrong logical value from a 3D matrix

1 vue (au cours des 30 derniers jours)
Leonardus Yudha Septian Sutanto
Modifié(e) : DGM le 17 Août 2021
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 commentaires
Yazan
Yazan le 17 Août 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)
Leonardus Yudha Septian Sutanto
I see, I got it now! Thanks a lot!

Connectez-vous pour commenter.

Réponses (1)

DGM
DGM le 17 Août 2021
Modifié(e) : DGM le 17 Août 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)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by