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

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Srivardhan Gadila
Srivardhan Gadila el 27 de Mayo de 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 comentario
Steven Horstink
Steven Horstink el 5 de Jun. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by