Having trouble getting data into simulink from a simulink signal object

I'm quite new to simulink so I apologize if this is a silly question.
I'm trying to create a set of data in matlab, convert it into a bus, and create a simulink.signal so I can call it as a global variable with a Data store read block. I have been able to make this work with several types of imput data, but im having trouble making it work with timetables.
For a breif example of how im trying to do this and where im getting stuck:
Im starting with a struct ('dataTimeTables') that contains a seperate timetable for each column from a table ('dataRaw'), ends up being a 1x1 struct with 28 fields
%%%% making a bus
BusData = Simulink.Bus.createObject(dataTimeTables);
%%%% making that bus into a signal object
DataInSimulinkGlobal = Simulink.Signal;
DataInSimulinkGlobal.DataType = 'Bus : BusData';
DataInSimulinkGlobal.Complexity = 'real';
DataInSimulinkGlobal.Dimensions = 1;
DataInSimulinkGlobal.SampleTime = .02;
Now when i run it, it creates the bus and the signal in simulink with the correct dimentions and field names. I can use a data store read block to access the signal object and a bus selector to pull the appropriate bus with no errors, but when i try to inspect the data its all zeros.
My thought is that it's an issue with setting the Initial value of the signal, but i cant seem to figure out how to initalize it when it contains a timetable.
Ive tried alot of the obvious inital values ( 1, 0, -1, [ ], dataTimeTable.columnName.Properties.StartTime, dataTimeTable.columnName{1,1}, ...) without any luck
Wether this is acctually the issue, or if theres somthing else that im missing, im felling very stuck. Any help or direction would be hugely appreciated.
Also i understand that i could use a from workspace block, or a playback to make this work, which i will have to do if i can't get this to method to work, it will just cause some issues for me in later steps of my project so i would rather avoid it if possible.
Thanks Again,

 Accepted Answer

I think you have to use the "From Workspace" block to import the source data for the bus signals.
"BusData" in your code defines the bus. It is like the struct type in C code.
"DataInSimulinkGlobal" in your code defines the signal. It is like a variable in C code. You can specify the initial value through DataInSimulinkGlobal.InitialValue, but you can't set multiple (time, value) pairs to specify the time-varying values of the signal or the whole bus.
Use the "From Workspace" block to import the time-varying signal values for the whole bus, label the output signal of this block as "DataInSimulinkGlobal", as long as the data types, dimensions etc. match, then you should be all set.
This example might be helpful.
openExample('simulink/CreateNonvirtualBusFromStructureExample')

1 Comment

Thanks for your help!
I think your right about needing to use from workspace blocks. I was trying to avoid them because they're likely to cause problems as I scale up the project im working on, but your explination about the inital values makes sense to me, and is consistant with what I was experiencing when I was experimenting.
I hoped I was just missing somthing because buses and data stores seem to work so well with timetables, and I figured that would extend to simulink signals. oh well, it is what it is, thanks again for your help

Sign in to comment.

More Answers (0)

Categories

Find more on Large-Scale Modeling in Help Center and File Exchange

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!