MATLAB: Struct as input to a Simulink MATLAB Function block

simulinkstruc data simulink matlab function

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!

Best Answer

I found the answer myself on https://de.mathworks.com/help/simulink/ug/parameter-arguments-in-matlab-function-block-functions.html: In the MATLAB Function Block Editor, add an argument to the function header of the MATLAB Function block. The name of the argument must match the name of the masked parameter or MATLAB variable that you want to pass to the MATLAB Function block.
The new argument appears as an input port on the MATLAB Function block in the model.
In the MATLAB Function Block Editor, click Edit Data.
Select the new argument.
Set Scope to Parameter and click Apply.
The input port for the parameter argument no longer appears in the MATLAB Function block.