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

2 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 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 commentaire
Steven Horstink
Steven Horstink le 5 Juin 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by