23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Characters and Strings<br />

To Insert . . . Use . . .<br />

Horizontal tab \t<br />

Backslash \\<br />

Percent character %%<br />

Input Value Arguments<br />

In the syntax<br />

functionname(..., format_string, value1, value2, ..., valueN)<br />

The value arguments must immediately follow string in the argument<br />

list. In most instances, you supply one of these value arguments for each<br />

formatting operator used in string. Scalars, vectors, and numeric and<br />

character arrays are valid value arguments. You cannot use cell arrays or<br />

structures.<br />

If you include fewer formatting operators than there are values to insert,<br />

<strong>MATLAB</strong> reuses the operators on the additional values. This example shows<br />

two formatting operators and six values to insert into the string:<br />

sprintf('%s = %d\n', 'A', 479, 'B', 352, 'C', 651)<br />

ans =<br />

A = 479<br />

B = 352<br />

C = 651<br />

Sequential and Numbered Argument Specification.<br />

You can place value arguments in the argument list either sequentially (that<br />

is, in the same order in which their formatting operators appear in the string),<br />

or by identifier (adding a number to each operator that identifies which value<br />

argument to replace it with). By default, <strong>MATLAB</strong> uses sequential ordering.<br />

To specify arguments by a numeric identifier, add a positive integer followed<br />

by a $ sign immediately after the % sign in the operator. Numbered argument<br />

specification is explained in more detail under the topic “Value Identifiers”<br />

on page 2-52.<br />

2-45

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

Saved successfully!

Ooh no, something went wrong!