How to initialize number of iteration?

1 visualizzazione (ultimi 30 giorni)
Majid
Majid il 2 Dic 2022
Commentato: Majid il 3 Dic 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

Risposta accettata

Torsten
Torsten il 2 Dic 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 Commenti
Torsten
Torsten il 2 Dic 2022
I know too little about the underlying problem and the way you try to solve it to answer your question.
Majid
Majid il 3 Dic 2022
@Torsten no problem, thank you very much for you answer!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by