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

3 comentarios

Stephen23
Stephen23 el 21 de Mayo de 2020
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 el 21 de Mayo de 2020
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 el 21 de Mayo de 2020
& is the an element-wise operator.

Iniciar sesión para comentar.

 Respuesta aceptada

Steven Lord
Steven Lord el 22 de Mayo de 2020

1 voto

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

Más respuestas (0)

Etiquetas

Preguntada:

el 21 de Mayo de 2020

Respondida:

el 22 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by