engEvalString not working as expected
3 views (last 30 days)
Show older comments
Hi,
I am trying to call a MATLAB 2014b test script from my Visual Studio 2013 project. The project builds and runs fine without any error, but I think its not calling/executing my MATLAB script. Below is my C++ code snippet:
int main()
{
Engine *ep;
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
engEvalString(ep, "test");
printf("Hit return to continue\n\n");
fgetc(stdin);
engClose(ep);
return EXIT_SUCCESS;
}
test.m is suppose to create a plot, but I dont see any output plot when I run this code. I thought that the MATLAB Engine is not able to find the file and hence I added the path to MATLAB path as below:
engEvalString(ep, "addpath C:\Users\Projects\MATLAB");
engEvalString(ep, "test");
But the above also doesnt show the correct result. It looks like command engEvalString is not getting executed on MATLAB.
Any thoughts?
Thanks
0 Comments
Accepted Answer
More Answers (1)
James Tursa
on 11 Mar 2015
When the project is running and paused with the "Hit return to continue" message, the Engine window should be open. Click on that window and type "test" in the command line and see what happens (i.e., just try to manually run the test script).
3 Comments
James Tursa
on 11 Mar 2015
For the path problem, try the function form of the call instead, e.g.,
engEvalString(ep, "addpath('C:\Users\Projects\MATLAB')");
For the Access problem, you will have to determine what that is actually referring to (directory access?, file access? file already open? etc) and then proceed from there.
See Also
Categories
Find more on Call MATLAB from C in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!