How to create an independent loop?

조회 수: 4 (최근 30일)
Andrea Miceli
Andrea Miceli 2021년 9월 21일
편집: Rik 2021년 9월 21일
hi everyone,
I try to explain my problem in the simplest way,
I wrote a code and I need a part of this code to be repeated 200 times. I tried a 'for loop', but that's not what I'm looking for because every time it runs a new loop the variables get intertwined.
I need this part of the code to be repeated 200 times as if I were running the code for the first time. (I need 200 repetitions, each independent of the other). Is it possible to do this on matlab? thanks for your help
  댓글 수: 2
Voss
Voss 2021년 9월 21일
Sounds like you need to restore your variables to their initial state on each loop iteration.
Andrea Miceli
Andrea Miceli 2021년 9월 21일
yeah exactly

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2021년 9월 21일
편집: Rik 2021년 9월 21일
If you want something to be independent, you need to use a function:
for n=1:200
my_fun(n,struct_with_your_other_variables);
end
function my_fun(n,vars)
%your code depending on n goes here
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by