How to initialize number of iteration?

8 views (last 30 days)
Majid
Majid on 2 Dec 2022
Commented: Majid on 3 Dec 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

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!