필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to do the loop

조회 수: 1 (최근 30일)
Aswin Sandirakumaran
Aswin Sandirakumaran 2018년 5월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a vector A = [0,0,0] & B = [4,2,1]
i = 1:length(B) -->> I am not sure about this part
while (A(i) <= B(i))
A(i) = A(i) + 1;
end
I need to perform this while loop according to B values. To give you a clear picture; first while loop should consider B(1) which is 4. Therefore while loop should be carried out 4 times. here the output will of A will change to A = [4,0,0]. Once done, B(2)--> which is 2. So while loop should be done 2 times and o/p now will be A = [4,2,0] and then B(3) ---> which is 1. So the Final output of A will be [4,2,1] instead of [0,0,0].
  댓글 수: 1
Dennis
Dennis 2018년 5월 5일
to make your code work you just need to add 'for'
for it = 1:length(B)
while (A(it) <= B(it))
A(it) = A(it) + 1;
end
end
However it might be possible to avoid using multiple loops, depending on what you want to do. Right now A=B would do the trick but i assume thats not what you actually want.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by