Evaluate a list of functions without using feval in generated code for embedded application
显示 更早的评论
I want to generate a mex function to evaluate a list of matlab functions iterativeley. The functions to evaluate are stored in a cell variable 'functionsList', each element being the name of the function file (char type). The code below works fine but it uses the 'feval' function which is an extrinsic one.
function outputs = functionToGenerate(inputs)
global functionsList
outputs = inputs;
for i=1:length(functionsList)
outputs = feval(functionsList{i},outputs);
end
end
As the final goal is to use this code for embedded application I am looking for an alternate method. I tried to use the 'str2func' with the code below :
function outputs = functionToGenerate(inputs)
global functionsList
outputs = inputs;
for i=1:length(functionsList)
f = str2func(functionsList{i});
outputs = f(outputs);
end
end
but I get an error during code generation :
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
This error concerns the line using 'str2func'. Can anyone could tell me where does the error come from and how can I solve this?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!