Rename BUS

38 views (last 30 days)
Alexandre
Alexandre on 20 Feb 2012
Commented: Song Xianjun on 10 Apr 2024 at 8:18
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.

Accepted Answer

Andreas
Andreas on 20 Feb 2012
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

More Answers (1)

AbhimanyuSingh
AbhimanyuSingh on 11 May 2018
You can try following:
FA.cog = 0.374; FA.mass = 2000; TestObject=Simulink.Bus.createObject(FA);
controlName=eval(TestObject.busName); clear -regexp slBus;clear TestObject;
controlName, is the Name you want. For renaming Multiple bus object you have to loop.
  1 Comment
Song Xianjun
Song Xianjun on 10 Apr 2024 at 8:18
It's worked well,Thanks!

Sign in to comment.

Categories

Find more on Modeling in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!