You shouldn't use i
and j
as variables i
and j
as variables in MATLAB, as they are used to denote the imaginary unit (sqrt(-1)
).
In fact, the official MATLAB documentation warns you about it. It's better to use 1i
or 1j
for the imaginary unit.
The documentation says the performance is better, but that's not really true really true. The main problem however is that using those variable names
can result in some stange behavior. As i
is not undefined, you don't get the usual Undefined function or variable 'x'.
You shouldn't use i
and j
as variables in MATLAB, as they are used to denote the imaginary unit (sqrt(-1)
).
In fact, the official MATLAB documentation warns you about it. It's better to use 1i
or 1j
for the imaginary unit.
The documentation says the performance is better, but that's not really true. The main problem however is that using those variable names
can result in some stange behavior. As i
is not undefined, you don't get the usual Undefined function or variable 'x'.
You shouldn't use i
and j
as variables in MATLAB, as they are used to denote the imaginary unit (sqrt(-1)
).
In fact, the official MATLAB documentation warns you about it. It's better to use 1i
or 1j
for the imaginary unit.
The documentation says the performance is better, but that's not really true. The main problem however is that using those variable names
can result in some stange behavior. As i
is not undefined, you don't get the usual Undefined function or variable 'x'.
- 2.1k
- 1
- 18
- 34
are both false.
Since both conditions must be wrong, we must use We can disregard the &A < 0.75
part, since those elements are already set to (and)1
.
In plain text: The elements in result
shall be 1 if either A > 0.75
or A > 0.25
and B == 1
. Since the last part has an and in there, we must use &
.
It's a matter of preference, but you might want to do ... & B == true
alternatively ... & B == 1
for clarity. It's common to ignore the true
part, but it is a bit clearer to include it.
are both false.
Since both conditions must be wrong, we must use &
(and).
In plain text: The elements in result
shall be 1 if either A > 0.75
or A > 0.25
and B == 1
are both false. We can disregard the A < 0.75
part, since those elements are already set to 1
.
In plain text: The elements in result
shall be 1 if either A > 0.75
or A > 0.25
and B == 1
. Since the last part has an and in there, we must use &
.
It's a matter of preference, but you might want to do ... & B == true
alternatively ... & B == 1
for clarity. It's common to ignore the true
part, but it is a bit clearer to include it.
- 2.1k
- 1
- 18
- 34
results = (A > 0.75 | A < 0.25) % or `results = (A > 0.75) + (A < 0.25)
The part with A < 0.25
is irrelevant there, since those elements are already zero.
x | y
means x == true
and/or y == true
. So, it's enough that one of the conditions are true. If you do x & y
, then both x
and y
must be true.
Since you include the part with B
, you must add a term, the above line is not enough. First notnote that the part with B
is only relevant if the two conditions with in the previos line
A < 0.75
and
A > 0.25
are both false. If they are false
Since both conditions must be wrong,
then the values in we must use B&
that are 1 should result in a 1 in the corresponding position in result
(and).
In plain text: The important part to realize here is that this means that all values that are
1elements in Bresult
will alsoshall be 1 if either 1A > 0.75
inor resultA > 0.25
.andB == 1
resultsresult = ((A > 0.75) | (A <> 0.25 |& B))
A =
0.5688 568800 0.1622 162200 0.1656 165600 0.6892689200
0.4694 469400 0.7943 794300 0.6020 602000 0.7482748200
0.0119 011900 0.3112 311200 0.2630 263000 0.4505450500
0.3371 337100 0.5285 528500 0.6541 654100 0.0838
083800
B
B =
1 0 1 0
0 0 1 1
0 1 1 0
0 0 1 1
results = (A > 0.75 | A < 0.25 | B)
resultsres =
1 1 0 1 0 0
0 1 1 1
1 0 1 1 0
0 0 1 10
results = (A > 0.75 | A < 0.25) % or `results = (A > 0.75) + (A < 0.25)
x | y
means x == true
and/or y == true
. So, it's enough that one of the conditions are true. If you do x & y
, then both x
and y
must be true.
Since you include the part with B
, you must add a term. First not that the part with B
is only relevant if the conditions with in the previos line are false. If they are false,
then the values in B
that are 1 should result in a 1 in the corresponding position in result
. The important part to realize here is that this means that all values that are
1 in B
will also be 1
in result
.
results = (A > 0.75 | A < 0.25 | B)
A =
0.5688 0.1622 0.1656 0.6892
0.4694 0.7943 0.6020 0.7482
0.0119 0.3112 0.2630 0.4505
0.3371 0.5285 0.6541 0.0838
B
B =
1 0 1 0
0 0 1 1
0 1 1 0
0 0 1 1
results = (A > 0.75 | A < 0.25 | B)
results =
1 1 1 0
0 1 1 1
1 1 1 0
0 0 1 1
results = (A > 0.75) % or `results = (A > 0.75)
The part with A < 0.25
is irrelevant there, since those elements are already zero.
x | y
means x == true
and/or y == true
. So, it's enough that one of the conditions are true. If you do x & y
, then both x
and y
must be true.
Since you include the part with B
, you must add a term, the above line is not enough. First note that the part with B
is only relevant if the two conditions
A < 0.75
and
A > 0.25
are both false.
Since both conditions must be wrong, we must use &
(and).
In plain text: The elements in result
shall be 1 if either A > 0.75
or A > 0.25
andB == 1
result = ((A > 0.75) | (A > 0.25 & B))
A =
0.568800 0.162200 0.165600 0.689200
0.469400 0.794300 0.602000 0.748200
0.011900 0.311200 0.263000 0.450500
0.337100 0.528500 0.654100 0.083800
B =
1 0 1 0
0 0 1 1
0 1 1 0
0 0 1 1
res =
1 0 0 0
0 1 1 1
0 1 1 0
0 0 1 0