===================================
Note that ''='' is used in an assignment statement while ''=='' is used in a relation.
Relations may be connected or quantified by the logical operators
Operator Description
===================================
& and
| or
~ not
===================================
When applied to scalars, a relation is actually the scalar 1 or 0 depending on whether the relation is true or false (indeed, throughout this section you should think of 1 as true and 0 as false). For example
>> 3 < 5
ans =
1
>> a = (3 == 5)
a = 0
When logical operands are applied to matrices of the same size, a relation is a matrix of 0's and 1's giving the value of the relation between corresponding entries. For example:
>> A = [ 1 2; 3 4 ];
>> B = [ 6 7; 8 9 ];
>> A == B
ans =
0
|
0
|
0
|
0
|
|
>> A < B
|
ans =
|
|
1
|
1
|
1
|
1
|
To see how the other logical operators work, you should also try
>> ~A
>> A&B
>> A & ~B
>> A | B
>> A | ~A
-------------------------TASK 02--------------------------
For the arrays x and y given below, write matlab code to find all the elements in x that are greater than the corresponding elements in y.
x = [‐3, 0, 0, 2, 6, 8] y = [‐5, ‐2, 0, 3, 4, 10]
Dostları ilə paylaş: |