Dimension Error in Simulink
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using a Simulink matlab function block in MATLAB R2019a. I am currently getting the 2 errors mentioned below. How can I solve them? Thank you for any advice.
1) ERROR: Data 'Gamma' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field.
This is mostly due to the definition of Gamma on line 36. Here is the code...
function [Gamma, Lambda, minusA_times_x0, ci, Ci_1, Di] = interface(trajk_1, x0, params, Np, N_wp)
%% Predicted States
% x_pred = trajk_1(1:Np);
% y_pred = trajk_1(1:Np);
% theta_pred = trajk_1(1:Np);
%% States
x_0 = x0(1);
y_0 = x0(2);
phi_0 = x0(3);
v_0 = x0(4);
delta_0 = x0(5);
theta_0 = x0(6);
%% Parameters
Ts = params(1);
breaks = params(2:2+N_wp);
x5_p = params(2+N_wp+1:2+N_wp+(N_wp-1));
x4_p = params(2+N_wp+(N_wp-1)+1:2+N_wp+2*(N_wp-1));
x3_p = params(2+N_wp+2*(N_wp-1)+1:2+N_wp+3*(N_wp-1));
x2_p = params(2+N_wp+3*(N_wp-1)+1:2+N_wp+4*(N_wp-1));
x1_p = params(2+N_wp+4*(N_wp-1)+1:2+N_wp+5*(N_wp-1));
x0_p = params(2+N_wp+5*(N_wp-1)+1:2+N_wp+6*(N_wp-1));
y5_p = params(2+N_wp+6*(N_wp-1)+1:2+N_wp+7*(N_wp-1));
y4_p = params(2+N_wp+7*(N_wp-1)+1:2+N_wp+8*(N_wp-1));
y3_p = params(2+N_wp+8*(N_wp-1)+1:2+N_wp+9*(N_wp-1));
y2_p = params(2+N_wp+9*(N_wp-1)+1:2+N_wp+10*(N_wp-1));
y1_p = params(2+N_wp+10*(N_wp-1)+1:2+N_wp+11*(N_wp-1));
y0_p = params(2+N_wp+11*(N_wp-1)+1:2+N_wp+12*(N_wp-1));
qc_p = params(2+12*N_wp+1);
ql_p = params(2+12*N_wp+2);
rv_p = params(2+12*N_wp+3);
%% Test
temp = ones(81*Np,1);
Gamma = temp; % <============================================ LINE 36 (If Np in the above line is instead given some direct numeric value the code runs)
temp = ones(9*15,1);
Lambda = temp;
%% Evaluate Linear Parametric Cost Function Terms (Linearize at each prediction step)
a = [];
b = [];
for i = 1:15
idx = evaluate_pp_idx(breaks,theta_0);
temp = func_Gamma(qc_p, ql_p, theta_0, x0_p(idx), x1_p(idx), x2_p(idx), x3_p(idx), x4_p(idx), x5_p(idx), x_0, y0_p(idx), y1_p(idx), y2_p(idx), y3_p(idx), y4_p(idx), y5_p(idx), y_0);
a = [a;temp];
temp = func_Lambda(qc_p, ql_p, theta_0, x0_p(idx), x1_p(idx), x2_p(idx), x3_p(idx), x4_p(idx), x5_p(idx), x_0, y0_p(idx), y1_p(idx), y2_p(idx), y3_p(idx), y4_p(idx), y5_p(idx), y_0);
b = [b;temp];
end
% Gamma = a;
% Lambda = b;
%% Evalaute Linear System Model (Linearize at each time step)
minusA_times_x0 = ones(6,1);
ci = ones(6,1);
Ci_1 = ones(6,9);
Di = ones(6,9);
end
2) ERROR: Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
ERROR: Dimension 1 is fixed on the left-hand side but varies on the right ([1215 x 1] ~= [:? x 1]). Function 'Trajectory Generation/LMPC_LA/LMPC/MATLAB Function' (#188.1736.1741), line 52, column 1: "Gamma"
This is also mostly due to the definition of Gamma on line 52 this time. Here is the code (with just one line (52) uncommented and using direct numeric value instead of Np, rest is same as above)...
function [Gamma, Lambda, minusA_times_x0, ci, Ci_1, Di] = interface(trajk_1, x0, params, Np, N_wp)
%% Predicted States
% x_pred = trajk_1(1:Np);
% y_pred = trajk_1(1:Np);
% theta_pred = trajk_1(1:Np);
%% States
x_0 = x0(1);
y_0 = x0(2);
phi_0 = x0(3);
v_0 = x0(4);
delta_0 = x0(5);
theta_0 = x0(6);
%% Parameters
Ts = params(1);
breaks = params(2:2+N_wp);
x5_p = params(2+N_wp+1:2+N_wp+(N_wp-1));
x4_p = params(2+N_wp+(N_wp-1)+1:2+N_wp+2*(N_wp-1));
x3_p = params(2+N_wp+2*(N_wp-1)+1:2+N_wp+3*(N_wp-1));
x2_p = params(2+N_wp+3*(N_wp-1)+1:2+N_wp+4*(N_wp-1));
x1_p = params(2+N_wp+4*(N_wp-1)+1:2+N_wp+5*(N_wp-1));
x0_p = params(2+N_wp+5*(N_wp-1)+1:2+N_wp+6*(N_wp-1));
y5_p = params(2+N_wp+6*(N_wp-1)+1:2+N_wp+7*(N_wp-1));
y4_p = params(2+N_wp+7*(N_wp-1)+1:2+N_wp+8*(N_wp-1));
y3_p = params(2+N_wp+8*(N_wp-1)+1:2+N_wp+9*(N_wp-1));
y2_p = params(2+N_wp+9*(N_wp-1)+1:2+N_wp+10*(N_wp-1));
y1_p = params(2+N_wp+10*(N_wp-1)+1:2+N_wp+11*(N_wp-1));
y0_p = params(2+N_wp+11*(N_wp-1)+1:2+N_wp+12*(N_wp-1));
qc_p = params(2+12*N_wp+1);
ql_p = params(2+12*N_wp+2);
rv_p = params(2+12*N_wp+3);
%% Test
temp = ones(81*15,1);
Gamma = temp; % <============================================ LINE 36
temp = ones(9*15,1);
Lambda = temp;
%% Evaluate Linear Parametric Cost Function Terms (Linearize at each prediction step)
a = [];
b = [];
for i = 1:15
idx = evaluate_pp_idx(breaks,theta_0);
temp = func_Gamma(qc_p, ql_p, theta_0, x0_p(idx), x1_p(idx), x2_p(idx), x3_p(idx), x4_p(idx), x5_p(idx), x_0, y0_p(idx), y1_p(idx), y2_p(idx), y3_p(idx), y4_p(idx), y5_p(idx), y_0);
a = [a;temp];
temp = func_Lambda(qc_p, ql_p, theta_0, x0_p(idx), x1_p(idx), x2_p(idx), x3_p(idx), x4_p(idx), x5_p(idx), x_0, y0_p(idx), y1_p(idx), y2_p(idx), y3_p(idx), y4_p(idx), y5_p(idx), y_0);
b = [b;temp];
end
Gamma = a; % <============================================ LINE 52
% Lambda = b;
%% Evalaute Linear System Model (Linearize at each time step)
minusA_times_x0 = ones(6,1);
ci = ones(6,1);
Ci_1 = ones(6,9);
Di = ones(6,9);
end
1 commentaire
Pravin Jagtap
le 2 Août 2019
First error shows that the variable ‘gamma’ is changing its size, but it is defined as a fixed size variable in the Model Explorer.
Make sure to check the Variable-Size box in the Model Explorer for ‘gamma’.
For that follow:
View-> Model Explorer -> Model Explorer -> check ‘MATLAB function’-> click on ‘Support variable-size arrays’ checkbox
Error 2 is also linked with the same issue of ‘variable-size arrays’. It may help to resolve both errors.
Réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!