MATLAB: How to define a structure variable in a block using Simulink 7.2 (R2008b)

simulink

I want to know if I can define a structure variable inside a block in Simulink and use the same for code generation.

Best Answer

In order for you to use a structure type object in Simulink, you would have to first create a Simulink.Signal object first:
 
mysig=Simulink.Signal
and then change the datatype of the signal to the StructType that you have defined as following:
mysig.DataType='s'
Please also note that the following limitations of StructType :
1. Simulink.Parameter does not support StructType
2. Only user-written S-functions can handle signals of type StructType whereas regular Simulink blocks like a Gain block does not support StructType.
Please look at the example of using using custom data type in C MEX S-functions in the link below
Also refer the following documentation for more on registering custom data types using the macro ssRegisterTypeFromNamedObject: