Chapter 4 : Programming with Matlab Flashcards
equal to
==
not equal to
~=
greater than or equal to
> =
less than or equal to
<=
less than
greater than
<
>
NOT
~
returns an array as the same dimension as A; the new array has 1s where A is 0 and 0s where A is nonzero
~A
AND
&
A & B
returns an array of the same dimension as A and B; then new array has 1s where both A and B have nonzero elements and 0s where either A or B is 0
short circuit AND
&&
operator for scalar logical expressions. returns true if both A and B evaluate true, and false if they do not
A && B
OR
|
A || B
operator for scalar logical expressions returns true if either A or B or both evaluate to true, and false if they do not
what is the order of precedence for operator types?
- parenthesis, starting with inner most pair
- arithmetic operators and logical NOT; evaluated left to right
- relational operators evaluated from left to right
- logical AND
- logical OR
what is the format for if then statements
if STATEMENTS EXPRESSION
STATEMENT GROUP 1
end
what is the format for an else statement
if LOGICAL EXPRESSION STATEMENT GROUP 1 else STATEMENT GROUP 2 end
what is the format for an elseif statement?
if STATEMENTS EXPRESSION STATEMENT GROUP 1 elseif LOGICAL EXPRESSION 2 STATEMENT GROUP 2 else STATEMENT GROUP 3 end
What is required after every if then statement?
end
except an elseif
what is the typical structure for a loop?
for LOOP VARIABLE = M:S:N
STATEMENTS
end
what does the function ‘break’ do?
the program execution will jump to the ‘end’