Execute string containing MATLAB expression.
EVAL(s), where s is a string, causes MATLAB to execute
the string as an expression or statement.
EVAL(s1,s2) provides the ability to catch errors. It
executes string s1 and returns if the operation was
successful. If the operation generates an error,
string s2 is evaluated before returning. Think of this
[X,Y,Z,...] = EVAL(s) returns output arguments from the
expression in string s.
The input strings to EVAL are often created by
concatenating substrings and variables inside square
brackets. For example:
Generate a sequence of matrices named M1 through M12:
for n = 1:12
eval(['M' num2str(n) ' = magic(n)'])
Run a selected M-file script. The strings making up
the rows of matrix D must all have the same length.
D = ['odedemo '
n = input('Select a demo number: ');
Read and process files with names data1.dat, data2.dat, ...
k = 0;
k = k+1;
datak = ['data' int2str(k)];
filename = [datak '.dat'];
if ~exist(filename), break, end
eval(['load ' filename]);
X = eval(datak);
% Process data in matrix X.
See also LASTERR , FEVAL .