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.

Regular Expressions<br />

expr = [p1 ', ' p2 ', ' p3 ', ' p4];<br />

As the following results demonstrate, you can make your output easier to<br />

work with by using named tokens:<br />

loc1 = regexp(str1, expr, 'names')<br />

loc1 =<br />

adrs: '134 Main Street'<br />

city: 'Boulder'<br />

state: 'CO'<br />

zip: '14923'<br />

loc2 = regexp(str2, expr, 'names')<br />

loc2 =<br />

adrs: '26 Walnut Road'<br />

city: 'Topeka'<br />

state: 'KA'<br />

zip: '25384'<br />

loc3 = regexp(str3, expr, 'names')<br />

loc3 =<br />

adrs: '847 Industrial Drive'<br />

city: 'Elizabeth'<br />

state: 'NJ'<br />

zip: '73548'<br />

Conditional Expressions<br />

With conditional expressions, you can tell <strong>MATLAB</strong> to match an expression<br />

only if a certain condition is true. A conditional expression is similar to an<br />

if-then or an if-then-else clause in programming. <strong>MATLAB</strong> first tests the<br />

state of a given condition, and the outcome of this tests determines what, if<br />

anything, is to be matched next. The following table shows the two conditional<br />

syntaxes you can use with <strong>MATLAB</strong>.<br />

3-55

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

Saved successfully!

Ooh no, something went wrong!