How to initialize number of iteration?

6 Ansichten (letzte 30 Tage)
Majid
Majid am 2 Dez. 2022
Kommentiert: Majid am 3 Dez. 2022
Hello!
i ran my program code for 100 iterations in order to check result as function of variable A using this command :
A_100_iteration=[];
Result_100_iteration =[];
for n=1:100
%my program
A_100_iteration=[A_100_iteration,A] ; %first variable
Result_100_iteration=[Result_100_iteration,Result] ; %
end
Now i have t to change a new variable in my program denoted "B" whish is a vector [1*3600] ,but just the first element B(1) which is varied from [0 to 1000] as follow [0,20,40,60,80,100,..].
the first element B(1) is already initialized in my code, but i'm asking if it is possible to do a loop for in order to change each time.
for example ,
do 100 iteration,
B(1)=0,
do 100 iteration,
B(1)=20,
do 100 iteration,
B(1)=40
...
i'm looking for an easy method to just display the 100 iterations for each new value of B(1).
I hope that all is clear,
Thanks in advance

Akzeptierte Antwort

Torsten
Torsten am 2 Dez. 2022
A_100_iteration = cell(51,1);
Result_100_iteration = cell(51,1);
for ib = 1:51
B(1) = (ib-1)*20;
for n = 1:100
%my program,e.g.
A = 1;
Result = 1;
A_100_iteration{ib}=[A_100_iteration{ib},A] ; %first variable
Result_100_iteration{ib}=[Result_100_iteration{ib},Result] ; %
end
end
A_100_iteration{3}
Result_100_iteration{3}
  7 Kommentare
Torsten
Torsten am 2 Dez. 2022
I know too little about the underlying problem and the way you try to solve it to answer your question.
Majid
Majid am 3 Dez. 2022
@Torsten no problem, thank you very much for you answer!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by