How to emulate global/persistent class objects in Simulink blocks

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?

Antworten (0)

Kategorien

Mehr zu Simulink Coder finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 31 Jan. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by