I am using MATLAB function block for linprog as follows but this error occurred-Size mismatch for MATLAB expression 'linprog'. Expected = 1x1 Actual = 2x1

조회 수: 3 (최근 30일)
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

답변 (1개)

Tejas
Tejas 2024년 11월 14일
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);

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by