I looking for an explanation in a granular level to understand what the following code means:
idx=y==100;
From what I understand, it is taking a derivative of a variable x, setting it equal to y, equal to 100. Although, I'm not too sure what the purpose of this code would be.
CodePudding user response:
For idx=y==100;
MATLAB performs the following steps:
- It determines which of the two operators,
==
and=
is invoked first: Since the==
operator has a higher precedence than the=
operator, it selectsy==100
. To learn about operator precedence, you can have a look at https://www.mathworks.com/help/matlab/matlab_prog/operator-precedence.html. - The operation
y==100
, then comparesy
to100
and returns logical array of the same size asy
having1
at position wherey
is equal to100
and0
at other positions. To learn more about the==
operator you can have a look at https://www.mathworks.com/help/matlab/ref/eq.html. - Finally, MATLAB invokes the
=
operator:idx=
assigns the result ofy==100
to the variableidx
.