MATLAB: Is it possible to use the function EML.CSTRUCTNAME with Simulink Bus objects

simulink

I have a model that contains an Embedded MATLAB Function block with the following code
function y = foo()
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
a.one = int32(10);
a.two = 5;
eml.cstructname(a,'myBus');
y = a;
I would like the output signal to be a Simulink bus object.

Best Answer

It is possible to use Simulink bus objects as output signal types from Embedded MATLAB function blocks that use the EML.CSTRUCTNAME function. To do so the the structure that is named in the CSTRUCTNAME function must match the bus object exactly.
For the example given above a bus object must be defined in the workspace with the name 'myBus' and have the fields 'one' with a data type of int32 and 'two' with a data type double.
Once the bus is defined you can open the model explorer and click on the Embedded MATLAB Function icon in the Model Hierarchy window. Then, specify the output variable's data type to be 'Bus: myBus'.
For more information on creating bus objects see the documentation section titled 'Using the Bus Editor'. You can also execute to following in a MATLAB (2008a) command window:
web([docroot '/toolbox/simulink/ug/brin2jr-1.html'])