Is it possible to have a structure as an input and use its fields as constants in Simulink?

2 Ansichten (letzte 30 Tage)
Suppose I define in a script the structure
par.amplitude = 10;
par.raise = 20;
and then run the Simulink model as in the picture below. The model below gives an error, obviously: the question is, how should I build such a model such that it works as expected? Is this even possible?

Akzeptierte Antwort

Srivardhan Gadila
Srivardhan Gadila am 27 Mai 2020
And the following code might help you:
par.amplitude = 10;
par.raise = 20;
parBusInfo = Simulink.Bus.createObject(par)
parBus = evalin('base',parBusInfo.busName)
  1 Kommentar
Steven Horstink
Steven Horstink am 5 Jun. 2020
My apologies for my late response. I found the answer already and it works like a charm. At first I created the bus objects and fields myself and composed them as one big bus object which will have to exactly match the input structure, then I discovered the shortcut you're referring to which is A LOT simpler and removes the "danger" of mismatching (and spend some time debugging). Since it's exactly what you answered, I'll definitely accept your answer :)
Weird, however, how I spend a few hours scouring the internet for a solution, while the second link you included would've been exactly what I needed.
Also, I had some trouble understanding what a "bus" was. Now that I've worked with it, I suppose I understand, but the first time I read about it was very confusing...
Finally, I'd like to ask about
parBus = evalin('base',parBusInfo.busName)
What does that do?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by