필터 지우기
필터 지우기

Converting a for loop into a while loop?

조회 수: 2 (최근 30일)
Jeff Smith
Jeff Smith 2018년 4월 10일
답변: KSSV 2018년 4월 10일
If I have the for loop:
for i=1:3
for j=2:4
A(i,j)=B(i+2,j+1);
end
end
How could I convert this into a while loop? I've tried:
i=0;
j=1;
while (i<4 && j<4)
i=i+1;
j=j+1;
A(i,j)=B(i+2,j+1);
end
But its not giving the same results. This is also assuming A and B are 5x5 arrays.

채택된 답변

KSSV
KSSV 2018년 4월 10일
i = 1 ;
while i <=3
j = 2 ;
while j <=4
A(i,j) = B(i+2,j+1) ;
j = j+1 ;
end
i = i+1 ;
end
But you need not use a loop to achieve this. You can straight away use indices.

추가 답변 (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