how velocize operation boolean
显示 更早的评论
回答(2 个)
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 个评论
How is a-n equal to what you have wrote?
n=6;
a=[1 0 1 1 0];
b=a-n
pipor
2023-9-6
a=[0.3 1 0 3 9]
n=6
b=a<n
a>0
b
find((a==0)&(~(b==0)))
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
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.
The index is at the start, that is, where the zeros are.
5 个评论
pipor
2023-9-6
" i want find element that: a==0 and b==1"
Try this:
a= [1 1 0 1 1]; % (is correct)
b = [1 1 1 1 0]; % (is correct)
logicalIndexes = (a == 0) & (b == 1)
linearIndexes = find((a == 0) & (b == 1))
This should all be covered in the learning on-ramp. To learn other fundamental concepts, invest 2 hours of your time here:

pipor
2023-9-6
pipor
2023-9-6
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
