23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4 M-File <strong>Programming</strong><br />

strcmp str1 str2<br />

ans =<br />

0 (unequal)<br />

% Command syntax<br />

How <strong>MATLAB</strong> Recognizes Function Calls That Use Command<br />

Syntax<br />

It can be difficult to tell whether a <strong>MATLAB</strong> expression is a function call<br />

using command syntax or another kind of expression, such as an operation on<br />

one or more variables. Consider the following example:<br />

ls ./d<br />

Is this a call to the ls function with the directory ./d as its argument? Or is it<br />

a request to perform elementwise division on the array that is the value of the<br />

ls variable, using the value of the d variable as the divisor?<br />

This example might appear unambiguous because <strong>MATLAB</strong> can determine<br />

whether ls and d are functions or variables. But that is not always true.<br />

Some <strong>MATLAB</strong> components, such as M-Lint and the Editor/Debugger, must<br />

operate without reference to the <strong>MATLAB</strong> path or workspace. <strong>MATLAB</strong><br />

therefore uses syntactic rules to determine when an expression is a function<br />

call using command syntax.<br />

The rules are complicated and have exceptions. In general, when <strong>MATLAB</strong><br />

recognizes an identifier (which might name a function or a variable), it<br />

analyzes the characters that follow the identifier to determine what kind of<br />

expression exists. The expression is usually a function call using command<br />

syntax when all of the following are true:<br />

1 The identifier is followed immediately by white space.<br />

2 The characters following the white space are not parentheses or an<br />

assignment operator.<br />

3 The characters following the white space are not an operator that is<br />

itself followed by additional white space and then by characters that can<br />

legitimately follow an operator.<br />

4-60

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

Saved successfully!

Ooh no, something went wrong!