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

2 次查看(过去 30 天)
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?

采纳的回答

Srivardhan Gadila
Srivardhan Gadila 2020-5-27
And the following code might help you:
par.amplitude = 10;
par.raise = 20;
parBusInfo = Simulink.Bus.createObject(par)
parBus = evalin('base',parBusInfo.busName)
  1 个评论
Steven Horstink
Steven Horstink 2020-6-5
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by