Struct as input to a Simulink MATLAB Function block
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (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
il 29 Ago 2018
0 voti
Johannes Köppern
il 29 Ago 2018
0 voti
2 Commenti
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
il 24 Apr 2020
Modificato: Nicolò Binda
il 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
il 30 Ago 2018
0 voti
Categorie
Scopri di più su Simulink Functions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!