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 />

function varargout = byDiag(a)<br />

varargout{1} = ' With VARARGOUT constructed by diagonal ...';<br />

for k = -4:4<br />

varargout{k + 6} = diag(a, k);<br />

end<br />

Call the function with five output variables. Again, <strong>MATLAB</strong> assigns<br />

elements of varargout according to the manner in which it was constructed<br />

within the function:<br />

[text d1 d2 d3 d4] = byDiag(magic(5))<br />

text =<br />

With VARARGOUT constructed by diagonal ...<br />

d1 =<br />

11<br />

d2 =<br />

10<br />

18<br />

d3 =<br />

4<br />

12<br />

25<br />

d4 =<br />

23<br />

6<br />

19<br />

2<br />

Calling External Functions<br />

The <strong>MATLAB</strong> external interface offers a number of ways to run external<br />

functions from <strong>MATLAB</strong>. This includes programs written in C or Fortran,<br />

methods invoked on Java or COM (Component Object Model) objects,<br />

functions that interface with serial port hardware, and functions stored in<br />

shared libraries. The <strong>MATLAB</strong> External Interfaces documentation describes<br />

these various interfaces and how to call these external functions.<br />

4-67

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

Saved successfully!

Ooh no, something went wrong!