How to emulate global/persistent class objects in Simulink blocks
Show older comments
My goal is to have a Simulink block (with m- or s-functions) that uses an instance of a class to store data and to perform computations in the underlying computation block. More precisely, I want to have something like
function [<outputs>] = block_function(<inputs>)
class_object = SomeClass();
<some computations with class_object>
end
in a Simulink block. The problem here is that 'class_object' is created in each function call, though. Global class objects are not supported for code generation, as well as persistent variables in the function. So I see no way at the moment to avoid the repeated generation of the class object 'class_object'. Maybe MATLAB does some optimizations in the generated code, but at first this seems to be very inefficient, especially if there is large data behind 'class_object'.
Does anyone have a proposal on how to implement this scenario more efficiently and finally generate code with it?
Answers (0)
Categories
Find more on Simulink Coder 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!