Clear Filters
Clear Filters

Problen with using varsize

2 views (last 30 days)
Grek Vardugin
Grek Vardugin on 4 Nov 2018
Answered: Grek Vardugin on 12 Nov 2018
Hello! I need some problems with using function varsize. This is my code:
lambda = struct('lower', 0, 'upper', 0, 'eqlin', 0, 'ineqlin', 0);
coder.varsize('lambda.lower', [1,inf]);
coder.varsize('lambda.upper', [1,inf]);
coder.varsize('lambda.eqlin', [1,inf]);
coder.varsize('lambda.ineqlin', [1,inf]);
[xopt,zmin,exitflag,output2,lambda] = linprog(C1,A,B,[],[],LB1,[],[],options);
fprintf(1,Out1,xopt,zmin);
fprintf(1,'ExitFlag= %d\nIterats= %d\n',exitflag,output2.iterations);
fprintf(1,'Algorithm - %s\n',output2.algorithm);
fprintf('Dual problem\n');
fprintf(1,'y1 = %1.5f\ny2 = %1.5f\ny3 = %1.5f\n', lambda.ineqlin(1),lambda.ineqlin(2), lambda.ineqlin(3));
And I see this error:
MATLAB expression 'lambda.lower' is not of the correct size: expected
[1x1] found [3x1].
I try to compile MEX-function with codegen. What's wrong?

Accepted Answer

Grek Vardugin
Grek Vardugin on 12 Nov 2018
My solution.
if isempty(Aeq)
valueAeq = [];
else
valueAeq = ones(size(Aeq,1), 1);
end
if isempty(A)
valueA = [];
else
valueA = ones(size(A,1), 1);
string1 = [ ' ',num2str(A(1,1)),'x1)'];
end
lambda = struct('lower', ones(size(C,2),1), 'upper', ones(size(C,2),1), 'eqlin', valueAeq, 'ineqlin', valueA);
[xopt,zmin,exitflag,output2,lambda] = linprog(C,A,B,Aeq,Beq,LB1,[],[],options);
If someone knows how to do it better, I will be happy to see a solution.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!