MATLAB: In a MATLAB Engine application on a Windows XP platform, why does a call to CD or ADDPATH within “engEvalString” fail at runtime

engdemoengdemo.cMATLAB

In a MATLAB Engine (R2006b) application on a Windows XP platform, I am making calls to both CD and ADDPATH. The application compiles without error, but the CD and ADDPATH commands are failing silently at runtime without interrupting the application or generating warning or error messages.

Best Answer

As the argument to "engEvalString" is a string, the backslash "\" on Windows needs to be escaped.
For CD:
engEvalString(ep, "cd( 'c:\\matlab\\test' );");
For ADDPATH:
engEvalString(ep, "addpath( 'c:\\matlab\\test' );");