Struct as input to a Simulink MATLAB Function block
Show older comments
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!
Accepted Answer
More Answers (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
on 29 Aug 2018
0 votes
Johannes Köppern
on 29 Aug 2018
0 votes
2 Comments
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
on 24 Apr 2020
Edited: Nicolò Binda
on 24 Apr 2020
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ò
Johannes Köppern
on 30 Aug 2018
0 votes
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!