Load Bus Object into Simulink using From Workspace

64 visualizaciones (últimos 30 días)
Marcus
Marcus el 3 de Mzo. de 2014
Respondida: timo el 1 de Sept. de 2019
I am having trouble loading a bus object into Simulink using 'from workspace.' I found a reference link showing how to do this at: http://blogs.mathworks.com/seth/2012/05/14/how-to-load-and-save-bus-signal-data/
For completeness here is the code:
N=100;
dt=0.1;
t=(0:N)'*dt;
myBus.a = timeseries(sin(t),t);
myBus.b = timeseries(rand(size(t)),t);
However when try to run the simulation I receive the following error:
Error evaluating parameter 'OutDataTypeStr' in 'untitled/From Workspace'
Caused by: Cannot resolve variable 'busObj'
I am using MATLAB 2012b. I tried setting the output data type to double but then I receive the following error:
The From Workspace block 'untitled/From Workspace' is configured to load a structure of timeseries objects from the workspace, but its data type 'double' is not a bus data type. To load bus data in a From Workspace block, set the "Output data type" to 'Bus: BusObjectName'.
I have no idea what I am doing wrong. I followed the details in the tutorial shown above but for some reason Simulink will not run without error. I am also noticing in Simulink that the connection line is staying black, it is not turning into the bus object connector.
I don't want to use the method outlined in Import Structures of timeseries Objects for Buses because that involves going through the import GUI and the simulation I am working is complicated.
Can someone please help me?

Respuestas (2)

Gina
Gina el 19 de Feb. de 2015
I had the exact same problem. And it was not obvious how to solve. Finally discovered that just making a bus in the Simulink model isn't enough. After you make the bus, you need to add it to the Base Workspace. Select from Simulink pull down menu select Edit -> Bus Editor. Here, you should see NO BUS defined. Go ahead and add the one you just made into the Base Workspace. You can name the signals. Now the bus should show up in the Bus Object menu for saving to and reading from workspace. This was done with Matlab 2014a.
  1 comentario
Andy Isfanuti
Andy Isfanuti el 9 de Feb. de 2018
Editada: Andy Isfanuti el 9 de Feb. de 2018
You can also create this bus object programatically, in base workspace: https://www.mathworks.com/help/simulink/ug/create-bus-objects-programmatically.html
In this case it would be:
% first element
BusElem(1) = Simulink.BusElement;
BusElem(1).Name = 'a';
BusElem(1).Dimensions = 1;
BusElem(1).DimensionsMode = 'Fixed';
BusElem(1).DataType = 'double';
BusElem(1).SampleTime = -1;
BusElem(1).Complexity = 'real';
% second element
BusElem(2) = Simulink.BusElement;
BusElem(2).Name = 'b';
BusElem(2).Dimensions = 1;
BusElem(2).DimensionsMode = 'Fixed';
BusElem(2).DataType = 'double';
BusElem(2).SampleTime = -1;
BusElem(2).Complexity = 'real';
% bus object definition
BusObjectName = Simulink.Bus;
BusObjectName.Elements = BusElem

Iniciar sesión para comentar.


timo
timo el 1 de Sept. de 2019
...this doesnt work in a MATLAB function ...anyone has a clue why ?
Undefined function or variable 'Simulink.BusElement'. Function 'Subsystem/MATLAB Function' (#393.61.80), line 3, column 18: "Simulink.BusElement" Launch diagnostic report.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by