How do I input a struct as an input to a custom matlab simulink function?

I have a struct which defines constants and vectors for aerodynamics surfaces on an aircraft. How do I create a bus with a struct input?

回答 (2 件)

Alok Virkar
Alok Virkar 2020 年 2 月 26 日
編集済み: Alok Virkar 2020 年 2 月 26 日
Im not too familiar with Stateflow or using a bus... Here is what I have done so far
I have a struct called s2
Used the line below to create a bus object from s2 struct and changed the bus name to 's2Bus'
s2Bus = Simulink.Bus.createObject(s2);
s2Bus.busName = 's2Bus'
Then I went to model explorer, found my function, added data, and changed the data type to bus object, and added the name there as shown in the image below.
However now I am getting a s2bus error:
Sai Sri Pathuri
Sai Sri Pathuri 2020 年 2 月 26 日

0 投票

When you created the bus object using Simulink.Bus.createObject, a structure s2Bus and a bus object slBus1 are created. Assigning the bus name as 's2Bus' has only changed the field 'busName' in s2Bus structure but the name of bus object is still slBus1. (as you can see in below figure)
Hence, you need to set the datatype of bus input as Bus: slBus1.

3 件のコメント

Alok Virkar
Alok Virkar 2020 年 3 月 1 日
Thank you, I fixed that and looks like the bus(and virtual bus) is reading in the format correctly but not the values.When I look at the values of the bus while running, it sets all my values to 0. Im not quite sure why this is the case because I have set up the values in a initialization script from matlab.
So how do I make simulink read in the correct values here? Is a bus the correct format here?
Sai Sri Pathuri
Sai Sri Pathuri 2020 年 3 月 4 日
Can you attach the simulink model?
Alok Virkar
Alok Virkar 2020 年 4 月 28 日
編集済み: Alok Virkar 2020 年 4 月 28 日
ok sorry late response here, but I realised I didnt need a bus to do what I was looking for.
I solved the issue by simply changing the function input's scope to parameter.

サインインしてコメントする。

カテゴリ

質問済み:

2020 年 2 月 23 日

編集済み:

2020 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by