Simulink error "variable-size matrix but its size is specified as inherited or fixed"
Show older comments
I'm building a MPC controller for a state space plant (
,
, with
,
,
).
,
, with I implemented the MPC as Matlab function, whose inputs are
- enable (a flag that enables the controller. If it is equal to false, then the outputs are set equal to zero);
- X_ref (a vector of size
, with the reference state value for each step in the prediction horizon N); - U_ref (a vector of size
, with the reference input value for each step in the prediction horizon N); - x_k ( a vector of the current state
); - mpc (a structure with the data for the MPC implementation and all the preprocessed matrices; this is the only function input of type "parameter data"; it's value is read from matlab workspace).
The output is the vector
, that is the control action for the plant. It is constructed in the following way
, that is the control action for the plant. It is constructed in the following wayfunction u_k = mpc_controller(enable, X_ref, U_ref, x_k, mpc)
if enable
...
[z_opt, ~, flag] = quadprog((H+H')./2, f, Ain, bin, Aeq, beq, lb, ub, [], options);
else
idx = 1;
z_opt = zeros(mpc.nu, 1);
end
u_k = z_opt(idx:(idx+mpc.nu-1));
where mpc.nu is
, while idx is a index appositely constructed in the code.
The same function works perfectly when running in Matlab, but once exported into simulink in the Matlab function, the following error rises:
Error: 'u_k' is inferred as a variable-size matrix, but its size is specified as inherited or fixed. Verify 'u_k' is defined in terms of non-tunable parameters, or select the 'Variable Size' check box and specify the upper bounds in the Size box.
I fixed the u_k value in the property inspector (inside the matlab function block) equal to mpc.nu, that is the actual length of the output, since it cannot have the feature "variable size" because one of the block in series with the matlab function block is a demux.
Do you have any idea on how to manage this problem? Thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on Controller Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

