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.
回答 (2 件)
Kaustubha Govind
2011 年 11 月 28 日
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 件のコメント
Elhadjit Tamsir Diop
2016 年 7 月 28 日
It worked for me too!!Thanks a lot
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!