This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.


Execute MATLAB expression in specified workspace


evalin(ws, expression)
[a1, a2, a3, ...] = evalin(ws, expression)


evalin(ws, expression) executes expression, a character vector containing any valid MATLAB® expression using variables in the workspace ws. ws can have a value of 'base' or 'caller' to denote the MATLAB base workspace or the workspace of the caller function. You can construct expression by concatenating character vectors and variables inside square brackets:

expression = [charvec1, int2str(var), charvec2,...]

[a1, a2, a3, ...] = evalin(ws, expression) executes expression and returns the results in the specified output variables. Using the evalin output argument list is recommended over including the output arguments in the expression:

evalin(ws,'[a1, a2, a3, ...] = function(var)')

The above syntax avoids strict checking by the MATLAB parser and can produce untrapped errors and other unexpected behavior.


This example extracts the value of the variable var in the MATLAB base workspace and captures the value in the local variable v:

v = evalin('base', 'var');


evalin cannot be used recursively to evaluate an expression. For example, a sequence of the form evalin('caller', 'evalin(''caller'', ''x'')') doesn't work.

More About

collapse all


The MATLAB base workspace is the workspace that is seen from the MATLAB command line (when not in the debugger). The caller workspace is the workspace of the function that called the currently running function. Note that the base and caller workspaces are equivalent in the context of a function that is invoked from the MATLAB command line.

evalin('caller', expression) finds only variables in the caller's workspace; it does not find functions in the caller. For this reason, you cannot use evalin to construct a handle to a function that is defined in the caller.

If you use evalin('caller', expression) in the MATLAB debugger after having changed your local workspace context with dbup or dbdown, MATLAB evaluates the expression in the context of the function that is one level up in the stack from your current workspace context.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?