Borrar filtros
Borrar filtros

Rename BUS

17 visualizaciones (últimos 30 días)
Alexandre
Alexandre el 20 de Feb. de 2012
Comentada: Song Xianjun el 10 de Abr. de 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.

Respuesta aceptada

Andreas
Andreas el 20 de Feb. de 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

Más respuestas (1)

AbhimanyuSingh
AbhimanyuSingh el 11 de Mayo de 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 comentario
Song Xianjun
Song Xianjun el 10 de Abr. de 2024
It's worked well,Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by