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

조회 수: 8 (최근 30일)
Timo
Timo 2023년 2월 10일
댓글: Josh Chen 2023년 2월 13일
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?

답변 (1개)

Josh Chen
Josh Chen 2023년 2월 10일
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
Timo
Timo 2023년 2월 13일
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 2023년 2월 13일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dependency Analysis에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by