Filter löschen
Filter löschen

evaluate dynamic variables in a loop and assign each one with optimvar.

1 Ansicht (letzte 30 Tage)
Hi;
i created a number of variables like the following:
for j=1:N
eval(['b' num2str(j) '= j']);
end
i need to assign each b1,b2,b3,.... as the following inside the loop.
b1=optimvar('b1','Type','integer','LowerBound',0,'UpperBound',1);
b2=optimvar('b2','Type','integer','LowerBound',0,'UpperBound',1);
.
.
.
please help.
  4 Kommentare
Walter Roberson
Walter Roberson am 26 Jun. 2019
Cell array, or dynamic field names on a struct array.
mohammad alquraan
mohammad alquraan am 26 Jun. 2019
give me a hint how to start writing the code.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

infinity
infinity am 26 Jun. 2019
Hello,
This small example may help you
clear
N = 3;
b = cell(1,N);
for i = 1:N
a = sprintf('b%d',i);
b{i} = optimvar(a,'Type','integer','LowerBound',0,'UpperBound',1);
end

Weitere Antworten (0)

Kategorien

Mehr zu Performance and Memory 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!

Translated by