MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

2 Data Types A = 'fate'; B = 'cake'; A == B ans = 0 1 0 1 All of the relational operators (>, >=,

Characters and Strings A = isletter(mystring) A = 1 1 1 1 0 0 0 0 The first four elements in A are logical 1 (true) because the first four characters of mystring are letters. Searching and Replacing MATLAB provides several functions for searching and replacing characters in a string. (MATLAB also supports search and replace operations using regular expressions. See “Regular Expressions” on page 3-31.) Consider a string named label: label = 'Sample 1, 10/28/95'; The strrep function performs the standard search-and-replace operation. Use strrep to change the date from '10/28' to '10/30': newlabel = strrep(label, '28', '30') newlabel = Sample 1, 10/30/95 findstr returns the starting position of a substring within a longer string. To find all occurrences of the string 'amp' inside label, use position = findstr('amp', label) position = 2 The position within label where the only occurrence of 'amp' begins is the second character. The strtok function returns the characters before the first occurrence of a delimiting character in an input string. The default delimiting characters are the set of white-space characters. You can use the strtok function to parse a sentence into words. For example, function allWords = words(inputString) remainder = inputString; allWords = ''; 2-59

2 Data Types<br />

A = 'fate';<br />

B = 'cake';<br />

A == B<br />

ans =<br />

0 1 0 1<br />

All of the relational operators (>, >=,

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

Saved successfully!

Ooh no, something went wrong!