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