How to input bus data (values) into my simulink model?

8 views (last 30 days)
So I have an inport that expects a bus signal. This bus signal is a "struct/bus object" which I have defined from a data dictionary.
Now what I need to do is to not only define/declare it (speaking like using the programming language C), but also create a variable from that "data type"/struct.
That struct then needs to be filled with actual values, so I can pass the values into the Simulink model. The values shall be generated by MATLAB.
So my actual question is:
  • How can I create a Bus/struct (that was defined in Simulink/Data dictionary) variable in MATLAB, fill it with values, and pass it into Simulink, so I can make simulations with it?
It does not seem like I can create a bus object from my defined Bus object (from my data dictionary). So how do I create a "Bus-Struct/Object" in MATLAB? Then, how do I fill the member variables of that Bus/Struct? It does not look like I can access the members directly. And afterwards: I need to save it to a *.mat file and load it into my Simulink model.
So basically what I want to do is the following (using c to illustrate my point):
/* Defined in simulink/data dictionary: */
typedef struct {
int x;
struct obj y;
double z;
} myBusStruct;
/* Declare struct in MATLAB and fill it with values */
myBusStruct mbs;
mbs.z = 1.3;
mbs.x = 7;
mbs.y = /* assign plausible value */;
/* Save to mat-file and load into Inports of Simulink model */
saveToMat(mbs);
Can anyone help me?

Answers (1)

Josh Chen
Josh Chen on 10 Feb 2023
Hey Timo,
If you have that bus/struct saved in Data dictionary, you should be able to bring it to MATLAB with "Simulink.data.dictionary.open". After that, you can access the specific struct or create a new one based on it. This page shows you how to access data dictionary programmatically.
Hope this helps,
Josh
  2 Comments
Timo
Timo on 13 Feb 2023
Thank you Josh,
well yeah it helped kind of. I now started to change to a *mat-File instead of a data dictionary. Now I can easily load the Bus object into my workspace and use it in Simulink. However, how can I now change the values of an object/struct created by this bus object?
I cant acess the members via dot operator. How can I access and modify the members values?
Josh Chen
Josh Chen on 13 Feb 2023
Hey Timo.
It is hard to explain without an example. But if you are looking for a doc page showing how to modify value for a Simulink.Bus, you can check this one.
Josh

Sign in to comment.

Categories

Find more on Dependency Analysis in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!