Code covered by the BSD License  

Highlights from
Bus X Struct

image thumbnail

Bus X Struct

by

 

12 Apr 2011 (Updated )

This example shows how to import Matlab Structs into Simulink by using BusObjects.

MyBusObj()
% by Gustavo Baldo Carvalho
% (GustavoBaldoCarvalho@yahoo.com)
% 05/05/2011
% This files loads the Bus object MyBusObj that defines the Bus MyBus
% which receives the imported struct MyStruct into Simulink.
% MyBusObj is composed by:
%   - a single element el1.
%   - a bus object MyBusObjA
%   - a bus object MyBusObjB 

function MyBusObj() 
% MyBusObj initializes a set of bus objects in the MATLAB base workspace 

% Bus object: MyBusObj 
clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'el1';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'double';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).SamplingMode = 'Sample based';

elems(2) = Simulink.BusElement;
elems(2).Name = 'A';
elems(2).Dimensions = 1;
elems(2).DimensionsMode = 'Fixed';
elems(2).DataType = 'MyBusObjA';
elems(2).SampleTime = -1;
elems(2).Complexity = 'real';
elems(2).SamplingMode = 'Sample based';

elems(3) = Simulink.BusElement;
elems(3).Name = 'B';
elems(3).Dimensions = 1;
elems(3).DimensionsMode = 'Fixed';
elems(3).DataType = 'MyBusObjB';
elems(3).SampleTime = -1;
elems(3).Complexity = 'real';
elems(3).SamplingMode = 'Sample based';

MyBusObj = Simulink.Bus;
MyBusObj.HeaderFile = '';
MyBusObj.Description = sprintf('');
MyBusObj.Elements = elems;
assignin('base', 'MyBusObj', MyBusObj)

Contact us