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.

2 Data Types<br />

while (any(remainder))<br />

[chopped,remainder] = strtok(remainder);<br />

allWords = strvcat(allWords, chopped);<br />

end<br />

The strmatch function looks through the rows of a character array or cell<br />

array of strings to find strings that begin with a given series of characters. It<br />

returns the indices of the rows that begin with these characters:<br />

maxstrings = strvcat('max', 'minimax', 'maximum')<br />

maxstrings =<br />

max<br />

minimax<br />

maximum<br />

strmatch('max', maxstrings)<br />

ans =<br />

1<br />

3<br />

Converting from Numeric to String<br />

The functions listed in this table provide a number of ways to convert numeric<br />

data to character strings.<br />

Function Description Example<br />

char<br />

int2str<br />

num2str<br />

mat2str<br />

Convert a positive integer to an equivalent<br />

character. (Truncates any fractional parts.)<br />

Convert a positive or negative integer to a<br />

character type. (Rounds any fractional parts.)<br />

Convert a numeric type to a character type of the<br />

specified precision and format.<br />

Convert a numeric type to a character type of the<br />

specified precision, returning a string <strong>MATLAB</strong><br />

can evaluate.<br />

[72 105] → 'Hi'<br />

[72 105] → '72 105'<br />

[72 105] →<br />

'72/105/' (format<br />

set to %1d/)<br />

[72 105] → '[72<br />

105]'<br />

2-60

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

Saved successfully!

Ooh no, something went wrong!