How do I generate code that does not copy read-only data accessed in a MATLAB Function block?

I have a MATLAB Function Block in a Simulink model that reads from a large amount of data. I would like to make sure that only one copy of this data exists in the generated code, to avoid unnecessary time and memory overhead.

How do I give the MATLAB Function Block access to this data without ever making a copy of it?

 Akzeptierte Antwort

For this application, you should use a "Simulink.Parameter". Create one in your workspace, and store your desired data into the Simulink Parameter's "Value". Then, in your MATLAB Function block, in the Symbols pane, add a new symbol of type "Parameter Data", with the same name as the Simulink Parameter you created. You can then access the parameter as if it was a function argument.
 
>> mySlParam = Simulink.Parameter;
>> mySlParam.Value = 5;

Weitere Antworten (0)

Kategorien

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

Produkte

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by