Struct as input to a Simulink MATLAB Function block
显示 更早的评论
Hi!
I want to simulate a physical system with the scalar state x, the parameters data and the differential equation dx/dt = dxdt(x,data), e. g.
function xDot = dxdt(x,data)
xDot=data.a+data.b*x;
I want to call this function from a Simulink Function block.
How can I hand the data struct into the Simulink block? Is there maybe a better way to store the model's parameters? Due to the type of the model's parameters a named way to store different types of parameters would be great. Having a vector to store the parameters is only my last resort.
Thank's in advance!
采纳的回答
更多回答(4 个)
Check below links:
To connect the structure input or output in a MATLAB function with Simulink, you must define a Simulink.Bus object in the base workspace. Then use this bus object as signal datra type for the signals which are to be connected to Matlab function.
Johannes Köppern
2018-8-29
0 个投票
2 个评论
If you have parameters on base workspace then you can access them directly in Matlab function (just like in stateflow).
- Open Model Explorer
- In Model Hierarchy window--> Select you s-function
- Add data --> Change data name to same as parameter name --> Select "Scope" as "Parameter".
Nicolò Binda
2020-4-24
编辑:Nicolò Binda
2020-4-24
Hi
I've got a structure in matlab and a bus with the same Hierarchy linket to an entity in simulink (i generate the bus from the struct and i selected in the entity generator as entity type "bus" and i choose the bus.
now i need to import data from the struct to the bus (so to each entity generated) but i'm not able to do this.
many thanks
Nicolò
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!