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!