MATLAB: How to make workspace variables appear as class members of a C++ class in generated code

matlab coder

I have a model which uses variables defined in the workspace. I am generating C++ code from this model. I would like the workspace variables to appear as class parameters/members inside the C++ class, that also can be tuned
What storage class or settings do I need to achieve this?

Best Answer

For getting per-instance members of a class,I have followed these steps:
1. In the Model Data editor, set these parameters to be of StorageClass Model Default
2. In Model configuration parameters (Model Settings) , under Code Generation->Optimization set the Default parameter behavior to be "Tunable"
The generated code creates a structure named - struct P_<model_name>_T_ in <model_name>.h. This structure contains the tunable parameters.
An instance of this structure is defined as a private static member of the class in<model_name>.h as shown below :
// private data and function members
private:
// Tunable parameters
static P_<model_name>_T <struct_name>;
The current limitation here is that it is not possible to generate these as non-static members of the class.