Using relative paths in function handles for Matlab compiler

2 ビュー (過去 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 Center および File ExchangeWaveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by