Issues iterating over list of functions using str2func with codegen
이전 댓글 표시
I want to use str2func to evaluate functions specified by strings in transpiled code. The basic setup is along the lines of
function output = computeFeatures(arbitraryData, funcList)
% arbitraryData = rand(100,1);
% funcList = {'max','min','mean','mode'};
% Pre-allocation
nFunc = length(funcList);
for iFunc = 1:nFunc
funcName = lower(funcList{iFunc});
funcHandle = str2func(funcName);
output.(upper(funcName))=funcHandle(arbitraryData);
end
end
However, when I try to use codegen I get the following error,
"Nonconstant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression."
I have not shown pre-allocation explicitly here, but I can if that is necessary.
Ultimately I would like to be able iterate over a list of functions (determined at compile time) with the same input and output data formats. The primary reason for this is to simplify development and avoid manually adding multiple new sections to my code base every time add a function to my "funcList".
All help is greatly appreciated.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Algorithm Design Basics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!