MATLAB Compiler how to use functions in single directory?

1 view (last 30 days)
Hi,
I've developed some software which utilises a modular approach, in that the directory structure is as follows:
Within the directory containing the compiled executable file, a directory named "Modules" exists. Within the "Modules" directory there is an ever-growing number of directories, named "Test1", "Test2" and so on. Within each of these is a series of functions. Within each directory, the function names will be the same. So for example, Module "Test1" will have "run.m" and "calculate.m", whereas Module "Test2" will also have "run.m" and "calculate.m".
Each module is selected by a listbox within a GUI. The path to these functions is determined depending upon which module within the listbox is selected.
While developing my software, I used the following code to add the path to the directory of functions that I would need, then I would perform the function (which was in this path I've just added), then after completion I would remove the path:
addpath(listboxPath);
run(args_in);
rmpath(listboxPath);
This worked great, until I tried to compile my software (with deploytool) in which I found that it doesn't like adding and removing paths.
Is there another way that I could point my script to look for functions in a certain directory? The issue I'm facing is that I have multiple functions with similar names (albeit in different directories) as the names must be standard.
Thanks very much in advance!

Answers (1)

Jan
Jan on 9 Oct 2018
Edited: Jan on 9 Oct 2018
Overloading the built-in function run is a bad idea and might cause problems, if you work with scripts. Selecting functions by adding the folders dynamically is not safe also. It would be a smarter approach to use different names for the functions.
It might be easy to write a small script, which includes the names of the folders in the names of the functions. Then replace
addpath(listboxPath);
run(args_in);
rmpath(listboxPath);
by:
fcn = str2func([listboxPath, '_run']);
feval(fcn);
Hmm, I'm not sure if this works. The compiler includes only files of functions, which are called, but here the function name is created dynamically. A wrapper might be working, although it is not nice:
switch listboxPath
case 'folder1'
folder1_run(args_in);
...
Or would working with packages solve the problem?
You see, the dynamic redefinition of the path causes troubles, because it is a kind of meta-programming. Maybe this is a good reason to start a restructuring of the code now.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!