1

I have a small code snippet that calls a matlab function (saved in its own .m file). The user can choose the matlab function to call and it may or may not be in MATLAB's default folder (~/Documents/MATLAB).

In the event that it's not in the default search path, I would like to add the function's containing folder to MATLAB's search path. When I try to do this using the Terminal (I am on a MAC), with this command:

/Applications/MATLAB_R2011b.app/bin/matlab -r "addpath(genpath('/Folder/Address/Here'))"

MATLAB launches, and I can see that the new address was successfully added to the search path.

However, when I try to run this command through the C++ program using this:

std::string  matlabFunctionPath = "/Folder/Address/Here"
std::string  addPathCommand = "/Applications/MATLAB_R2011b.app/bin/matlab -r \"addpath(genpath('"+ matlabFunctionPath + "')\"";
::popen(shellCommand.c_str(), "r"));

MATLAB does launch but the new address does not get added to the search path. What am I doing wrong here?

I appreciate the help.

1 Answer 1

1

You are missing the second closing )

std::string  addPathCommand = "/Applications/MATLAB_R2011b.app/bin/matlab -r \"addpath(genpath('"+ matlabFunctionPath + "'))\"";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.