Rename BUS
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexandre
am 20 Feb. 2012
Kommentiert: Song Xianjun
am 10 Apr. 2024
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 Kommentare
Akzeptierte Antwort
Andreas
am 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
0 Kommentare
Weitere Antworten (1)
AbhimanyuSingh
am 11 Mai 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 Kommentar
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!