필터 지우기
필터 지우기

Using relative paths in function handles for Matlab compiler

조회 수: 8 (최근 30일)
Wajahat Kazmi
Wajahat Kazmi 2017년 3월 12일
답변: Chris Volpe 2017년 4월 19일
Hi I am generating a deployable exe using Matlab Compiler (mcc). My code includes certain function handles whose files, in the target PCs, will be at different locations than the PC they were generated on. Matlab compiler generates an exe, successfully. However, it looks for the absolute paths of the files for the corresponding function handles.
I would be grateful, if someone can tell me:
1- How can I use relative paths in the function handles (since the .m files for the functions will be at a fixed relative location w.r.t the exe file but different absolute location on the target PCs)?
2- If I cannot, what is the best possible work around?
Best Regards Wajahat
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2017년 3월 13일
Wajahat - are these files chosen by the user through the GUI or do you really mean the m-files which would be packaged with the executable?
Wajahat Kazmi
Wajahat Kazmi 2017년 3월 13일
Hi Geoff
The m files will be packaged with the exe. Therefore, I can ensure fixed relative path for the m files w.r.t the exe.
But the entire package could be lying anywhere on the target PCs.
Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Wajahat Kazmi
Wajahat Kazmi 2017년 3월 13일
편집: Wajahat Kazmi 2017년 3월 13일
Hi
Seems like it is solved by using mcc with -a option followed by filename with path to the file containing function definition.
mcc -m -o MyExecFilename MyCode.m -I LibrariesToInclude -a LibrariesToInclude/FuncDefs/myFunc.m
So, even if the files are there in the path, function definitions whose function handles are being used, need to be explicitly added at the compile time.
Best Regards
Wajahat

추가 답변 (2개)

Steven Lord
Steven Lord 2017년 3월 13일
How are you creating these function handles? If the functions are on the MATLAB search path, neither you nor your program should care where the actual files are located. For instance, the vander function is on the MATLAB path and so this code doesn't care in which directory the actual vander.m is stored.
F = @vander;
F(1:5)
  댓글 수: 1
Wajahat Kazmi
Wajahat Kazmi 2017년 3월 13일
편집: Wajahat Kazmi 2017년 3월 13일
Hi Steven
I am creating the function handles the same way as you showed for vander(). It works perfectly within the Matlab environment. However, when an exe is created through Matlab compiler (mcc), that exe is unable to locate the file where the function handle points to.
Even if I create the path where function handle points to, and put the file there, still the exe cannot find the file. It produces an error, e.g. for a function handle @myfunc:
" could not find appropriate function on path loading function handle D:\My Documents\MATLAB\SomePath\MyFunctionDef.m>myfunc . "
The corresponding folders are also added to the path using 'isdeployed' in the startup.
Best Regards
Wajahat

댓글을 달려면 로그인하십시오.


Chris Volpe
Chris Volpe 2017년 4월 19일
Try adding:
%#function myfunc
to your code. This comment serves as a hint to the compiler that it should include the specified function in the compiled functions package even if it is not reached during dependency checking.

카테고리

Help CenterFile Exchange에서 MATLAB Runtime에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by