23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

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.

evalin<br />

2evalin<br />

Purpose Execute a string containing a <strong>MATLAB</strong> expression in a workspace<br />

Syntax evalin(ws,expression)<br />

[a1,a2,a3,...] = evalin(ws,expression)<br />

evalin(ws,expression,catch_expr)<br />

Description evalin(ws,expression) executes expression, a string containing any valid<br />

<strong>MATLAB</strong> expression, in the context of the workspace ws. ws can have a value<br />

of 'base' or 'caller' to denote the <strong>MATLAB</strong> base workspace or the workspace<br />

of the caller function. You can construct expression by concatenating<br />

substrings and variables inside square brackets:<br />

2-506<br />

expression = [string1,int2str(var),string2,...]<br />

[a1,a2,a3,...] = evalin(ws,expression) executes expression and<br />

returns the results in the specified output variables. Using the evalin output<br />

argument list is recommended over including the output arguments in the<br />

expression string:<br />

evalin(ws,'[a1,a2,a3,...] = function(var)')<br />

The above syntax avoids strict checking by the <strong>MATLAB</strong> parser and can<br />

produce untrapped errors and other unexpected behavior.<br />

evalin(ws,expression,catch_expr) executes expression and, if an error is<br />

detected, executes the catch_expr string. If expression produces an error, the<br />

error string can be obtained with the lasterr function. This syntax is useful<br />

when expression is a string that must be constructed from substrings. If this<br />

is not the case, use the try...catch control flow statement in your code.<br />

Remarks The <strong>MATLAB</strong> base workspace is the workspace that is seen from the <strong>MATLAB</strong><br />

command line (when not in the debugger). The caller workspace is the<br />

workspace of the function that called the M-file. Note, the base and caller<br />

workspaces are equivalent in the context of an M-file that is invoked from the<br />

<strong>MATLAB</strong> command line.<br />

Examples This example extracts the value of the variable var in the <strong>MATLAB</strong> base<br />

workspace and captures the value in the local variable v:<br />

v = evalin(‘base’,’var’);

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

Saved successfully!

Ooh no, something went wrong!