フィルターのクリア

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

1 回表示 (過去 30 日間)
Leonardus Yudha Septian Sutanto
Leonardus Yudha Septian Sutanto 2021 年 8 月 17 日
編集済み: DGM 2021 年 8 月 17 日
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
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)
Leonardus Yudha Septian Sutanto
Leonardus Yudha Septian Sutanto 2021 年 8 月 17 日
I see, I got it now! Thanks a lot!

サインインしてコメントする。

回答 (1 件)

DGM
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)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by