how to run a loop according to two different index at the same time?
조회 수: 12 (최근 30일)
이전 댓글 표시
For example:
i=[0 1 3 6 10]
j=[1 3 6 10 15]
Normally, when we use
'for index1=i
for index2=i
....
end
end'
then Matlab will firstly set i=0 and then run all the vaules from 1 to 15 in index2, and then goes back to i=1.
However, in my problem, I require that i and j to be executed simultaneously, like: when i=0, j=1, then i=1, j=3.
Anyone can tell me how to do with it?
many thanks
댓글 수: 0
채택된 답변
per isakson
2014년 12월 25일
편집: per isakson
2014년 12월 25일
One way:
ii = [0,1,3,6,10];
jj = [1,3,6,10,15];
for ix = 1 : length(ii)
ii(ix)
jj(ix)
end
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!