Rename BUS
35 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Andreas
2012-2-20
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
0 个评论
更多回答(1 个)
AbhimanyuSingh
2018-5-11
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!