Prerequisites for Matlab 2021 Models for integration into the Sim4Sys toolchain
TYPING OF INPUT AND OUTPUT

- Sizing and typing of input ports (Double click/Signal attributes):
- Simple value
- choose the type
- Float: choose double
- Integer, Enumeration: choose int16
- Boolean: choose boolean
- Select the port dimension [1;1]
- choose the type
- Vector
- Do not choose type (leave Inherit: auto)
- Select port size [X;Y]
- Y: the maximum number of elements in the vector
- X: element size
- Outputs
- Single value (same as input)
- Currently untreated vector
VECTOR MANAGEMENT
The difference in vector management between Matlab and C++ requires a strict process.
As you saw earlier, you must define a maximum size that allows you to size the array (matlab) corresponding to the vector. If it is an entry, the values not filled will be set to NaN. At the output, the values not filled in must also be set to NaN.

CONFIGURATION (TO DO IF YOU DID NOT USE NEW_SIMULINK_MODEL.SH SCRIPT)
First you have to chose the “Embedded Coder Apps” in the “APPS” tab of Simulink
Then in the new “C++ Code” tab, chose “Embedded C++ Code” with the first button.

With the same button, click on “Select System Target File” and chose “ert.tlc” with “Create Visual C/C++” as description.

After that, click on the “Code Interface” button and chose “Class Name & Namespace”

Verify that in “C++ Class Name” you have the structure “modelName” and “ModelClass” attached. “C++ Class Namespace” must stay empty.
Then with the same “Code Interface” button, chose “Code Mappings”

Check that your inputs and outputs are public or change them if not.
After that you can check the global settings by clicking on the “Settings” button

First go to the “Solver” tab
Check that you have “Fixed-step” in the “Solver Selection” “Type” combobox or change it if not.
Then go to the “Code Generation” tab
Here check the option “Generate code only” and uncheck “Generate makefile”
Then go to the “Interface” tab

Check the “variable-size signals” option
Then go to the “Identifiers” tab

Check that all the options have the settings like in the previous picture.
You can now click on “OK” to close the “Settings” panel.
You can generate the code by clicking on the “Generate Code” button

Chose “Generate Code”.
Once the code succesfully generated, you have to create a C++ project on Papyrus and import inside of it all the generated code. It is necessary to build a library containing the new Matlab project.
If you have already other Matlab projects, just past the new generated C++ code with the other Matlab projects code and rebuild it. If not you can create a new Project in designer

And then
Copy the generated code in this project.
If you need a .lib library you can change this setting by right clicking on the project in Papyrus and make the following modification
Once the new library succesfully generated, you have to copy it in "ExtraLibs/matlab/lib” and its code in “ExtraLibs/matlab/include”.
Check that the code generated from your UML project have the reference to the matlab library.
If you are already using other Matlabs, the references should be already there. If not you can add them.