필터 지우기
필터 지우기

"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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by