Struct as input to a Simulink MATLAB Function block
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (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
el 29 de Ag. de 2018
0 votos
Johannes Köppern
el 29 de Ag. de 2018
0 votos
2 comentarios
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
el 24 de Abr. de 2020
Editada: Nicolò Binda
el 24 de Abr. de 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
el 30 de Ag. de 2018
0 votos
Categorías
Más información sobre Simulink Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!