How to pass multiple parameters in Matlab coder?
2 次查看(过去 30 天)
显示 更早的评论
I developed two algorithms, let's call them EncoderClass.m and DecoderClass.m, that share their configuration (Configuration.m), which is a struct of structs (100~ Matlab system objects parameters, more or less). I wrote two functions:
% Encode.m
function [tx] = Encode(config, data)
...
end
% Decode.m
function [rx] = Decode(config, data)
...
end
and they look like that:
function [tx] = Encode(config, data) %#codegen
assert(isa(config, 'struct');
assert(isa(data, 'double'));
assert(length(data) == config.length);
e = EncoderClass(config);
tx = step(e, data);
end
And I would run it as follows:
data = genRandomData()
config = MyNewCoolConfig1
codegen Encode -args { coder.Constant(config), data } ...
Decode -args { coder.Constant(config), data }
After realizing that structs are not supported as constant in codegen (cannot remeber where I read it), I am having a hard time figuring out how to have a central file with my configuration and passing it somehow to my two Encoder and Decoder classes.
EncoderClass and DecoderClass have several Matlab objects in their belly, that's the reason why I need to have all those parameters and all at once.
Moreover, I'd like to have the possibility to have two different instances of EncoderClass and DecoderClass, so I cannot use globals (without touching Encoder and Decoder classes code at least), so I can write an export function as:
data1 = genRandomData()
data2 = genRandomData()
config1 = MyNewCoolConfig1
config2 = MyNewCoolConfig2
codegen Encode1 -args { coder.Constant(config1), data1 } ...
Decode1 -args { coder.Constant(config1), data1 } ...
Encode2 -args { coder.Constant(config2), data2 } ...
Decode2 -args { coder.Constant(config2), data2 }
The only solution I can think of is using a long list of parameters and passing it to the class constructor, which will should have enough intelligence to know to whom pass what.
I don't like this solution, so, is there – call it a best practice – a way to achieve what I am doing in a Matlab flavour?
0 个评论
回答(1 个)
Raghu Boggavarapu
2021-11-26
MATLAB Coder allows generating code with constant input configs. Starting with R2021b single MEX can be generated for multiple input argument input types, please refer to Generate Code for Multiple Entry-Point Functions - MATLAB & Simulink (mathworks.com)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!