02.03.2016 Views

MATLAB by rudra pratap

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

230 Errors<br />

2. » (x,y) = circlefn (S) ;<br />

??? (x,y) =circ lefn {S) ;<br />

r<br />

Error Expression or statement is incorrect - ,-possibly<br />

unbalanced L {", or t.<br />

Here <strong>MATLAB</strong> is confused with the list of variables because a list within<br />

parentheses represents matrix indices. When the variables represent output<br />

of a function or a list of vectors, they must be enclosed within square brackets.<br />

The correct command here is [x , y] =circlefn (5) ( circlefn is a user-written<br />

function) . When parentheses and brackets are mixed up, the same error message<br />

is displayed:<br />

» (x,y] = circlefn (S) ;<br />

??? (x,y] -circlefn (S) ;<br />

I<br />

Error : Expression or statement i s i ncorrect- -possibly . . .<br />

3.<br />

>> X 1:10;<br />

» v [0 3 6) i<br />

»X(v)<br />

??? Subscript indices must either be real pos itive integers<br />

or logicals.<br />

The first element of the index vector v is zero. Thus, we are trying to get the<br />

zeroth element of x. But zero is not a valid index for any matrix or vector<br />

in <strong>MATLAB</strong> except when it is a logical zero (i.e., zeros produced <strong>by</strong> logical<br />

operations) . The same problem arises when a negative number appears as an<br />

index. Also, of course, an error occurs when the specified index exceeds the<br />

corresponding dimension of the variable:<br />

»X (12)<br />

??? Attempted to access x(12) ; index out of bounds because numel (x) =l O .<br />

The examples given here for index-dimension mismatch are almost trivial.<br />

Most of the times, these problems arise when matrix indices are created, incremented,<br />

and manipulated inside loops.<br />

4. »X=1 :10; y=l02:-8;<br />

»X*Y<br />

??? Error using ==> mt ime s<br />

Inner matrix dimensions .mu.st agree .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!