MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Logic Statements


Use relational operators in conjunction with the logical operators A & B (AND), A | B
(OR), xor(A,B) (XOR), and ~A (NOT), to string together more complex logical
statements.

For example, you can locate where negative elements occur in two arrays.

A = [2 -1; -3 10]

A =

2 -1
-3 10

B = [0 -2; -3 -1]

B =

0 -2
-3 -1

A<0 & B<0

ans =

0 1
1 0

For more examples, see “Find Array Elements That Meet a Condition” on page 5-2.

See Also
eq | ge | gt | le | lt | ne

More About



  • “Array vs. Matrix Operations” on page 2-13

  • “Compatible Array Sizes for Basic Operations” on page 2-19

  • “MATLAB Operators and Special Characters” on page 2-2


2 Program Components

Free download pdf