A C/C++ program calls a MATLAB program which has "addpath"
Show older comments
Hi, there,
I encountered a problem when calling a standalone matlab porgram from a C program. I appreciate for any help.
Here is the C code:
main()
{
system(Dist.exe);
}
The following is the original .m code of the Matlab standalone program "Dist.exe".
Note that MATPOWER4.0 http://www.pserc.cornell.edu/matpower is a package of MATLAB for solving power flow in power system, and runpf and loadcase are both functions included in MATPOWER 4.0.
function Dist
if ~isdeployed
addpath('C:\Program Files\matpower4.0');
addpath('C:\Program Files\matpower4.0\t');
end
results = runpf('case30', mpoption('PF_ALG', 1));
afterDis = loadcase('case30');
The Command Prompt shows :
Error using==>loadcase at 244
loadcase: specified case not in MATLAB's search path
Error iin==>runpf at 123
It is obviously something wrong with addpath function. Although I have added if ~isdeployed , the problem is still there.
Answers (2)
Kaustubha Govind
on 28 Nov 2011
Adding the "if ~isdeployed" actually prevents the addpath commands from running in Dist.exe, because isdeployed returns true from the compiled application. However, even if you got rid of the "if" statement, the recommended way to add a directory to the MATLAB path is to actually package the required toolbox (MATPOWER4.0) files into the executable's CTF archive by using the "-a" option with the mcc command. You can now access this in the compiled executable by using a path relative to "ctfroot". For example, if your toolbox files are in a directory called "matpower4.0", you can use:
if ~isdeployed
addpath('C:\Program Files\matpower4.0');
else
addpath(fullfile(ctfroot, 'matpower4.0');
end
1 Comment
Elhadjit Tamsir Diop
on 28 Jul 2016
It worked for me too!!Thanks a lot
Jill
on 29 Nov 2011
Categories
Find more on Introduction to Installation and Licensing 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!