how velocize operation boolean

조회 수: 2 (최근 30일)
pipor
pipor 2023년 9월 6일
댓글: Image Analyst 2023년 9월 6일
N = 5
N = 5
a=[0.3 1 0 3 9]
a = 1×5
0.3000 1.0000 0 3.0000 9.0000
b=a<N
b = 1×5 logical array
1 1 1 1 0
find(b&(~a))
ans = 3

답변 (2개)

Image Analyst
Image Analyst 2023년 9월 6일
That code has nothing to do with your subject line. You want
logicalIndexes = a == 1
% or
linearIndexes = find(a == 1)
Same for b or any other variable.
  댓글 수: 5
pipor
pipor 2023년 9월 6일
a=[0.3 1 0 3 9]
a = 1×5
0.3000 1.0000 0 3.0000 9.0000
n=6
n = 6
b=a<n
b = 1×5 logical array
1 1 1 1 0
a>0
ans = 1×5 logical array
1 1 0 1 1
b
b = 1×5 logical array
1 1 1 1 0
find((a==0)&(~b==0))
ans = 3
Walter Roberson
Walter Roberson 2023년 9월 6일
a=[0.3 1 0 3 9]
a = 1×5
0.3000 1.0000 0 3.0000 9.0000
n=6
n = 6
b=a<n
b = 1×5 logical array
1 1 1 1 0
a>0
ans = 1×5 logical array
1 1 0 1 1
b
b = 1×5 logical array
1 1 1 1 0
find((a==0)&(~(b==0)))
ans = 3
but with b already being logical, b==0 is the same as ~b, and ~ of that is ~~b which for logical would be the same as b

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 9월 6일
You asked : "(i want to find idx element that change from 0 to 1 )"
So do this:
a = [5, 0, 1, 9, 0, 1];
index = strfind(a, [0, 1]) % Look for where [0, 1] occurs in the vector.
index = 1×2
2 5
The index is at the start, that is, where the zeros are.
  댓글 수: 5
pipor
pipor 2023년 9월 6일
excuse me a last question:
you use: (b == 1)) but b is logical
why you don't use (b) ..is the same?
Image Analyst
Image Analyst 2023년 9월 6일
(b == 1) will be logical because it's comparing the number to 1. b can be any data type, like double or integer or logical. The result will be true or false values, or 1 and 0 if you convert them to numbers, for example to multiply element-by-element by another numerical vector.
If b is logical than (b) is logical (already). If b is a double vector like [1,2,44,66] then b is not logical -- not true or false values.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by