MATLAB is unable to analyze code within statements called by
eval
. This prevents MATLAB from performing any
performance optimization and limits the guidance that the editor is able to
provide. This makes code less efficient and difficult to debug.
Furthermore, concatenated character vectors within an eval
statement are often difficult to read. This makes code less clear and causes
issues with sharing and maintaining code.
Use function syntax instead of using eval
to use command
syntax. This allows you to pass variables as inputs. For example:
Old | New |
---|---|
eval(['load ' theFilename])
|
load(theFilename)
|
eval(['save ' theFilename ' bigArray'])
|
save(theFilename, "bigArray")
|
eval(['cd ' labdata])
|
cd(labdata)
|
eval(['mex ', myOptions, ' -c modlab.c '])
|
mex(myOptions, "-c", "modlab.c")
|
eval(['clear selectMode ' tempvar])
|
clear("selectMode", tempvar)
|
For more information see Choose Command Syntax vs Function Syntax