MATLAB: Is it possible to create a BUS signal output of non double data type and have an input of data type double to a MATLAB Function block in Simulink 7.7 (R2011a)

simulink

I am trying to create a BUS signal output from a MATLAB Function block using the design pattern where the output structure is created using a STRUCT function in MATLAB. The non double data types only appear to be supported if the MATLAB Function block has NO inputs.
Adding an input to the MATLAB Function block gives compile errors.

Best Answer

When buidling a MATLAB Function block with multiple inputs of type double and BUS signal output of type other than double, you should explicitly specify the data of the inputs/outputs to the MATLAB Function block. The attached MATLAB file and Simulink model illustrate this functionality.
- In order to specify the data type of both Input/Output port of the Embedded MATLAB Function block, you have to follow the steps below:
a. Run the MATLAB file 'MakeTimestampBusObj.m' in order to create a 'bus_Timestamp' object in the workspace.
b. Open the Embedded MATLAB Function block. Select Tools -> Edit Data/Ports.
c. Choose each of the Input/Output ports and assign a data type. In this example, I have assigned the following:
'timestamp', Type: 'Bus: bus_Timestamp'
'out', Type: double (as opposed to 'Inherit from Simulink')
'u', Type: double
- Ensure that the input coming into the Embedded MATLAB Function block is of type double as specified above. To do so, double click the 'Constant' block, select 'Signal Attributes' tab and make the 'Output Data Type' double.