Unrecognized function or variable when using `str2func` in Docker container
4 views (last 30 days)
Show older comments
Hello. Inside a Docker container, I am attempting to run .m matlab files that are remotely pulled from a git repository so that a remote code can be changed continously without needed redeployment of a containerized instance of Matlab Production Server. Since addpath is not supported by the Matlab runtime, I created the following function to the run the pulled fnuctions that cannot be added the the path:
function [varargout] = evaluate_function_out_of_path(function_name, function_file_path, options)
arguments
function_name string
function_file_path string
options.function_inputs cell = {}
end
function_handle = str2func(function_name);
current_directory = cd;
cd(function_file_path);
[varargout{1:nargout}] = function_handle(options.function_inputs{:});
cd(current_directory);
end
While I am able to run evaluate_function_out_of_path locally without issue on pulled code not added to the search path, I am receving the following error when ran on a deployed Docker container:
Unrecognized function or variable 'my_function'
The code that I am pulling is not compiled. What I am worried about is that the pulled source code must be compiled first before it can be used during runtime. Is this assumption right? Oddly enough, I am able to run built in functions with str2func inside the container without any kind of compilation such as:
str2func("@() disp('hello world')")
Let me know if you need clarification; I'll edit the question accordingly. Thanks in advance!
8 Comments
Nicole Bonfatti
on 12 Apr 2024
Hi Chandler,
I'm the product manager for MATLAB Production Server and I'd be interested in hearing more about your use case for uncompiled code behind MATLAB Production Server, but I also wanted to address something I noticed in your OP:
You shouldn't need to redeploy your MATLAB Production Server container when you make changes to your deployed code. Provided you've packaged an updated deployable archive (CTF file) you should be able to map a volume into the container and replace the existing deployable archive in that volume without redeploying (or even restarting) the container itself.
Cheers,
Nicole
Answers (0)
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!