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.

3 Basic Program Components<br />

Function Output Separator<br />

Spaces are allowed when specifying a list of values to be returned by a<br />

function. You can use spaces to separate return values in both function<br />

declarations and function calls:<br />

function [data text] = xlsread(file, sheet, range, mode)<br />

Slash and Backslash — / \<br />

The slash (/) and backslash (\) characters separate the elements of a path or<br />

directory string. On Windows-based systems, both slash and backslash have<br />

the same effect. On UNIX-based systems, you must use slash only.<br />

On a Windows system, you can use either backslash or slash:<br />

dir([matlabroot '\toolbox\matlab\elmat\shiftdim.m'])<br />

dir([matlabroot '/toolbox/matlab/elmat/shiftdim.m'])<br />

On a UNIX system, use only the forward slash:<br />

dir([matlabroot '/toolbox/matlab/elmat/shiftdim.m'])<br />

Square Brackets — [ ]<br />

Square brackets are used in array construction and concatenation, and also in<br />

declaring and capturing values returned by a function.<br />

Array Constructor<br />

To construct a matrix or array, enclose all elements of the array in square<br />

brackets:<br />

A = [5.7, 9.8, 7.3; 9.2, 4.5, 6.4]<br />

Concatenation<br />

To combine two or more arrays into a new array through concatenation,<br />

enclose all array elements in square brackets:<br />

A = [B, eye(6), diag([0:2:10])]<br />

3-108

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

Saved successfully!

Ooh no, something went wrong!