I am using MATLAB function block for linprog as follows but this error occurred-Size mismatch for MATLAB expression 'linprog'. Expected = 1x1 Actual = 2x1
7 次查看(过去 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
0 个评论
回答(1 个)
Tejas
2024-11-14,6:35
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!