How to pass global variable into function in iteration or in loop. if someone knows please guide me.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
NIKET shah
am 26 Jun. 2018
Beantwortet: Walter Roberson
am 26 Jun. 2018
In the following code i want to pass global variable 'Lh' in loop to the main function. please guide if someone knows.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Jun. 2018
all_Lh = rand(24,1);
deci_vari = 3*1;
x0 = [1;2;3];
ub = ones(deci_vari,1);
lb = zeros(deci_vari,1);
Aeq = ones(1,deci_vari);
beq = ones(1,1);
for h=1:24
Lh = all_Lh(h);
options = optimoptions('fmincon','Algorithm','interior-point');
[x,fval] =fmincon(fun,x0,[],[],Aeq,beq,lb,ub,[],options);
c(h)=fval;
u1(h)=x(1,1);
u2(h)=x(2,1);
u3(h)=x(3,1);
%%u4(h)=x(4,1);
end
However we advise avoiding global variables. See instead
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!