Simulink function block array element operation with a fixed size

How can I achieve a array element opertion within the function block? The output of the function is sent to a integrator. Therefore, the output has a defined size.

 Accepted Answer

Change the code inside MATLAB function block to this
dy_dt = zeros(5,1);
dy_dt(1:3,:) = vars.g*u.*0.1.*y(1:3,:);
dy_dt(4:5,:) = vars.lambda*u.*0.1.*y(4:5,:);
Note that the first line is necessary for telling the compiler about the size of output dy_dt. Also, you cannot use zeros(var.size,1) since the compiler still cannot decide the value at compile time.

4 Comments

Thanks!! But is there any way that I can change the dy_dt size without going into the function block?
See the attached files. Note that, inside the MATLAB function block, I have defined a non-tunable parameter with the name of mySize (variable with this name also need to be defined in base workspace). You can check its properties by clicking the "Edit Data" button on the toolbar. This button will only appear when you open the MATLAB function block.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!