Struct as input to a Simulink MATLAB Function block
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (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
am 29 Aug. 2018
0 Stimmen
Johannes Köppern
am 29 Aug. 2018
0 Stimmen
2 Kommentare
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
am 24 Apr. 2020
Bearbeitet: Nicolò Binda
am 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
am 30 Aug. 2018
0 Stimmen
Kategorien
Mehr zu Simulink Functions finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!