Page 43 - MATLAB an introduction with applications
P. 43
28 ——— MATLAB: An Introduction with Applications
Table 1.26
Command Description
break Terminates the execution of MATLAB for and while loops. In
nested loops, break will terminate only the innermost loop in which
it is placed.
return Primarily used in MATLAB functions, return will cause a normal
return from a function from the point at which the return statement
is executed.
error (‘text’) Terminates execution and displays the message contained in text
on the screen. Note, the text must be enclosed in single quotes.
The MATLAB functions used are summarized in Table 1.27 below:
Table 1.27
Function Description
Relational A MATLAB logical relation is a comparison between two
operators variables and of the same size effected by one of the six
y
x
operators, <, <=, >, >=, = =, ~ =. The comparison involves
corresponding elements of and , and yields a matrix or scalar
x
y
of the same size with values of “true” or “false” for each of its
elements. In MATLAB, the value of “false” is zero, and “true”
has a value of one. Any non-zero quantity is interpreted as
“true”.
&
|
Combinatorial The operators (AND) and (OR) may be used to combine two
operators logical expressions.
all, any If x is a vector, all(x) returns a value of one if all of the
;
elements of are non-zero, and a value of zero otherwise. When
x
X is a matrix, all( ) returns a row vector of ones or zeros
X
obtained by applying all to each of the columns of . The
X
function any operates similarly if any of the elements of are
x
non-zero.
find If x is a vector, i = find(x) returns the indices of those elements
of x that are non zero (- i.e. , true). Thus, replacing all the negative
elements of x by zero could be accomplished by
i = find(x < 0);
x(i) = zeros(size(i));
If X is a matrix, [i, j] = find(X) operates similarly and returns
the row-column indices of non-zero elements.
if
if, else, elseif The several forms of MATLAB blocks are as follows:
ifvariable ifvariable 1 ifvariable 1
block of statements block of statements block of statements
Contd...
F:\Final Book\Sanjay\IIIrd Printout\Dt. 10-03-09