Why this rutine:
[0 0]<[1 1] & [0 0]<[-1 1]
return:
[0 1]
how work conditional operator & without if?

3 件のコメント

Stephen23
Stephen23 2020 年 5 月 21 日
These are the two inputs that you provided to the element-wise & operator:
>> [0 0]<[1 1]
ans =
1 1
>> [0 0]<[-1 1]
ans =
0 1
Are you uncertain how AND logic works? What do you expect the & operator to do?
daniel molina
daniel molina 2020 年 5 月 21 日
yes, I want to know how work AND in this case, that result this answer
>>[0 0]<[1 1] & [0 0]<[-1 1]
ans =
0 1
James Tursa
James Tursa 2020 年 5 月 21 日
& is the an element-wise operator.

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

 採用された回答

Steven Lord
Steven Lord 2020 年 5 月 22 日

1 投票

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

カテゴリ

タグ

質問済み:

2020 年 5 月 21 日

回答済み:

2020 年 5 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by