A C/C++ program calls a MATLAB program which has "addpath"

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)

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
HI, Kaustubha Govind,
Thanks for the help! It works.
I found out I forgot to include the matpower4.0 into CTF archive. I changed the mcc instruction while compiling my program:
mcc -m Dist.m -o Dist -a ./matpower4.0
Thanks a lot!!

Categories

Asked:

on 28 Nov 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!