& operator without if
1 view (last 30 days)
Show older comments
Why this rutine:
[0 0]<[1 1] & [0 0]<[-1 1]
return:
[0 1]
how work conditional operator & without if?
3 Comments
Accepted Answer
Steven Lord
on 22 May 2020
The & operator is an elementwise operator. Just like the + operator will add corresponding elements of its inputs when given two vectors of the same size:
x = [1 2 3];
y = [4 5 6];
z = x + y % z(1) = x(1) + y(1), z(2) = x(2) + y(2), z(3) = x(3) + y(3)
The & operator will take the and of the corresponding elements of its inputs.
a = [true false true];
b = [true true false];
c = a & b; % c(1) = a(1) & b(1), c(2) = a(2) & b(2), c(3) = a(3) & b(3)
The & operator with two scalars as input returns true if both its inputs are non-zero and false otherwise.
[ true & true; ... % true
true & false; ... % false
false & true; ... % false
false & false] % false
0 Comments
More Answers (0)
See Also
Categories
Find more on Monte Carlo Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!