MATLAB: Rename BUS

simulink

Hi, I am trying to generate a BUS from a Matlab structure to feed in a Simulink block. I am using this function:
FA.cog = 0.374; FA.mass = 2000: Simulink.Bus.createObject(FA);
It creates a BUS called 'slBus1' in the workspace but as I will have to create severals Buses, I want to control this name. Is there any way to set the name before calling the function or to change the name. It want to do this operation in Matlab before using Simulink.

Best Answer

Hi,
if you create a sample BUS with the bus editor you can export the BUS in the Model Explorer (Ctrl + H) of your Simulink Model (Base Workspace). It will generate an .m-file where you can set the bus names and run on model startup:
% -------------------------------------------------------------------

% MATLAB file generated by Simulink.saveVars
% -------------------------------------------------------------------
FA = Simulink.Bus;
FA.Description = '';
FA.DataScope = 'Auto';
FA.HeaderFile = '';
saveVarsTmp{1} = Simulink.BusElement;
saveVarsTmp{1}.Name = 'cog';
saveVarsTmp{1}.DataType = 'double';
saveVarsTmp{1}.Complexity = 'real';
saveVarsTmp{1}.Dimensions = 1;
saveVarsTmp{1}.DimensionsMode = 'Fixed';
saveVarsTmp{1}.SamplingMode = 'Sample based';
saveVarsTmp{1}.SampleTime = -1;
saveVarsTmp{1}(2, 1) = Simulink.BusElement;
saveVarsTmp{1}(2, 1).Name = 'mass';
saveVarsTmp{1}(2, 1).DataType = 'double';
saveVarsTmp{1}(2, 1).Complexity = 'real';
saveVarsTmp{1}(2, 1).Dimensions = 1;
saveVarsTmp{1}(2, 1).DimensionsMode = 'Fixed';
saveVarsTmp{1}(2, 1).SamplingMode = 'Sample based';
saveVarsTmp{1}(2, 1).SampleTime = -1;
FA.Elements = saveVarsTmp{1};
clear saveVarsTmp;
Regards, Andreas