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.

Calling Functions<br />

e = polyeig(A0, A1, A2)<br />

Function calls written in command syntax pass all arguments as string<br />

literals. This expression passes the strings 'mydata.mat', 'x', 'y', and'z'<br />

to the save function:<br />

save mydata.mat x y z<br />

The following examples show the difference between passing arguments in<br />

the two syntaxes.<br />

Passing Arguments — Example 1. Calling disp with the function syntax,<br />

disp(A), passes the value of variable A to the disp function:<br />

A = pi;<br />

disp(A)<br />

3.1416<br />

% Function syntax<br />

Calling it with the command syntax, disp A, passes the string 'A':<br />

A = pi;<br />

disp A<br />

A<br />

% Command syntax<br />

Passing Arguments — Example 2. Passing two variables representing<br />

equal strings to the strcmp function using function and command syntaxes<br />

gives different results. The function syntax passes the values of the<br />

arguments. strcmp returns a 1, which means they are equal:<br />

str1 = 'one';<br />

str2 = 'one';<br />

strcmp(str1, str2)<br />

ans =<br />

1 (equal)<br />

% Function syntax<br />

The command syntax passes the names of the variables, 'str1' and 'str2',<br />

which are unequal:<br />

str1 = 'one';<br />

str2 = 'one';<br />

4-59

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

Saved successfully!

Ooh no, something went wrong!