I am using MATLAB function block for linprog as follows but this error occurred-Size mismatch for MATLAB expression 'linprog'. Expected = 1x1 Actual = 2x1
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function s1 = fcn(Iref,Ib)
%#codegen
coder.extrinsic('linprog');
s1=zeros();
A = [0 0;0 0];
b = [0 0];
Aeq = [0 0];
beq = 0;
lb = [-5,-5];
ub = [5,5];
f = [Iref -Ib];
%Solve the linear program.
[s1] = linprog(f,A,b,Aeq,beq,lb,ub);
end
0 comentarios
Respuestas (1)
Tejas
el 14 de Nov. de 2024
Hello Gurparas,
The error indicates that the MATLAB Function block expects the output variable to be 1x1 in size, but the 'linprog' function actually returns a 2x1 output. This mismatch is causing the issue.
The problem arises because the output variable 's1' was initially set to a size of 1x1.
s1=zeros();
In a MATLAB Function block, a variable can only change size during simulation if the 'Support variable-size array' block property is enabled. For more details, you can refer to this documentation:
web(fullfile(docroot, 'simulink/ug/declare-variable-size-inputs-and-outputs.html'));
To fix this issue, set the size of the output variable 's1' to 2x1 beforehand.
s1=zeros(2,1);
0 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!