Using relative paths in function handles for Matlab compiler

2 visualizaciones (últimos 30 días)
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 comentarios
Geoff Hayes
Geoff Hayes el 13 de Mzo. de 2017
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 el 13 de Mzo. de 2017
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.

Iniciar sesión para comentar.

Respuesta aceptada

Wajahat Kazmi
Wajahat Kazmi el 13 de Mzo. de 2017
Editada: Wajahat Kazmi el 13 de Mzo. de 2017
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

Más respuestas (2)

Steven Lord
Steven Lord el 13 de Mzo. de 2017
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 comentario
Wajahat Kazmi
Wajahat Kazmi el 13 de Mzo. de 2017
Editada: Wajahat Kazmi el 13 de Mzo. de 2017
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

Iniciar sesión para comentar.


Chris Volpe
Chris Volpe el 19 de Abr. de 2017
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.

Community Treasure Hunt

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

Start Hunting!

Translated by