evalin
Same as eval except variable or expression is evaluated in context. Context is either 'caller' or 'base'.
Syntax
evalin(context, try, catch)
Inputs
- context
- Can be either 'caller' or 'base'.
- try
- Script statements that will be executed in the proper scope.
- catch (optional)
- Script statements that will be executed if an error occurs while executing try.
Examples
Caller evalin example:
function tocall
evalin('caller', 'x=3;');
end
function go
x=2;
tocall
x
end
x=1;
go;
x
x = 3
x = 1
Base evalin
example:
function tocall
evalin('base', 'x=3;');
end
function go
x=2;
tocall
x
end
x=1;
go;
x
x = 2
x = 3