필터 지우기
필터 지우기

How do I do a For Loop with two variables?

조회 수: 1 (최근 30일)
Helena
Helena 2018년 6월 1일
댓글: Helena 2018년 6월 1일
I want the loop to do for i=1:1:41 and for j=1:1:41, that is, the loop runs using i=1 and j=1, then i=2 and j=2 etc.
When I try the below nested function I get an infinite loop! for i=1:1:41 for j=1:1:41 Function end end
Can anyone help? Thanks!
  댓글 수: 2
Stephen23
Stephen23 2018년 6월 1일
@Helena: if i always equals j, why use two variables?
Helena
Helena 2018년 6월 1일
They're not the same, two different variables!

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

답변 (1개)

ES
ES 2018년 6월 1일
편집: ES 2018년 6월 1일
Then you dont need two for loops.
for i=1:41
j=i;
....do something
...
end
By the way, i and j are poor choice of variable names!
  댓글 수: 2
Helena
Helena 2018년 6월 1일
Now I'm getting the error 'Subscript indices must either be real positive integers or logicals.'
Helena
Helena 2018년 6월 1일
j is a date if that helps!

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

카테고리

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