Changing size of variable inside Matlab function in SIMULINK

2 次查看(过去 30 天)
Dear Matlab community
I am dealing with the following issue. I used the matlab function block inside SIMULINK which looks the following:
function du_llm2 = fcn(Yref,x,dztrack,PhiU2,PhiZ2,F2,H2,Qy2,Nc,dUmin,Umin,dUmax,Umax,Ymin,Ymax,M_du,M_u,C1)
nu = 3;
dU2 = zeros(nu*Nc,1);
du_llm2 = zeros(nu,1);
M_y = [-PhiU2; PhiU2];
M = [M_u;M_du;M_y];
gamma_du = [-dUmin; dUmax];
gamma_u = [ -Umin + C1*du_llm2; Umax - C1*du_llm2];
gamma_y = [ -Ymin + F2*x + PhiZ2*dztrack; Ymax - F2*x - PhiZ2*dztrack];
gamma = [gamma_u;gamma_du;gamma_y];
% % % % % % % % % % % % % % % % % %
M(isnan(gamma),:) = [];
gamma(isnan(gamma)) = [];
% % % % % % % % % % % % % % % % % %
coder.extrinsic('quadprog');
my_opt = optimoptions('quadprog');
% my_opt.Algorithm = 'interior-point-convex';
my_opt.Algorithm = 'active-set';
my_opt.Display = 'off';
% my_opt.MaxIterations = 1000;
% my_opt.OptimalityTolerance = 1e-5;
% my_opt.ConstraintTolerance = 1e-5;
f2 = -PhiU2' * Qy2 * ( Yref - F2*x - PhiZ2*dztrack);
% dU = -H2\f; % -inv(H)*f
dU2 = quadprog(H2,f2,M,gamma,[],[],[],[],dU2,my_opt);
du_llm2 = dU2(1:nu,1);
end
Basically, the problem here is that the size of variables inside the matlab function in SIMULINK are not allowed to change but cleaning M and gamma of the NaN values is essential for the further process. Is there any way to circumvent that?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2023-7-18

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by