"any" returns the wrong logical value from a 3D matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Yazan
2021-8-17
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)
回答(1 个)
DGM
2021-8-17
编辑:DGM
2021-8-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!