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 />

ans =<br />

g11n<br />

Using a dynamic expression ${num2str(length($2))} enables you to base<br />

the replacement expression on the input string so that you do not have to<br />

change the expression each time. This example uses the dynamic syntax<br />

${cmd} from the second table shown above:<br />

match_expr = '(^\w)(\w*)(\w$)';<br />

replace_expr = '$1${num2str(length($2))}$3';<br />

regexprep('internationalization', match_expr, replace_expr)<br />

ans =<br />

i18n<br />

regexprep('globalization', match_expr, replace_expr)<br />

ans =<br />

g11n<br />

Dynamic Operators for the Match Expression<br />

There are three types of dynamic expressions you can use when composing a<br />

match expression:<br />

• “Dynamic Expressions that Modify the Match Expression — (??expr)” on<br />

page 3-61<br />

“Dynamic Commands that Modify the Match Expression — (??@cmd)” on<br />

page 3-61<br />

“Dynamic Commands that Serve a Functional Purpose — (?@cmd)” on<br />

page 3-62<br />

The first two of these actually modify the match expression itself so that it can<br />

be made specific to changes in the contents of the input string. When <strong>MATLAB</strong><br />

evaluates one of these dynamic statements, the results of that evaluation are<br />

included in the same location within the overall match expression.<br />

The third operator listed here does not modify the overall expression, but<br />

instead enables you to run <strong>MATLAB</strong> commands during the parsing of a<br />

regular expression. This functionality can be useful in diagnosing your<br />

regular expressions.<br />

3-60

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

Saved successfully!

Ooh no, something went wrong!