WHILE loop with a condition on a vector and Scalar

조회 수: 4 (최근 30일)
Fidele Adanvo
Fidele Adanvo 2020년 10월 16일
댓글: Fidele Adanvo 2020년 10월 17일
PacksA=zeros(1,10);
j=1;
n=1;
B=10
while PacksA(n,n:j)<B
i=i+1;
j=j+1;
if j>10
break
end
#instruction
end
n=n+1
PacksA(1:n,1:j)=PacksA
basically.
First itinerary of the while
Compare the first element of the matrix PacksA(1,1) with B.
if true, execute instructions inside the while
update the value of PacksA
if false, exit the while and increment n, and the value of PacksA(1,1) is updated in PacksA
Again compares the value of PacksA(1,1) updated with B and others the value PacksA(1,2) with B
if they are true, execute statements inside the while
update the values of PacksA that meets
if they are false, exit the while and increase n and the value of PacksA(1,1) or/and PacksA(1,2) is updated in PacksA
Again compares the value of PacksA(1,1) updated with B and others the value PacksA(1,2) updated with B, and others the value PacksA(1,3) with B
if they are true, execute statements inside the while
update the values of PacksA that meets
if they are false, exit the while and increase n and the value of PacksA(1,1) or/and PacksA(1,2) or/and PacksA(1,3) is updated in PacksA
when the values PacksA are updated, it is not compared any more and the process continues up to 10.
  댓글 수: 2
Konstantin
Konstantin 2020년 10월 17일
Are you speaking about something like this?
while all( PacksA(n,n:j) ) < B ) % all elements must be smaller than B
or
while any( PacksA(n,n:j) <B ) % any of lements must be smaller then B
Fidele Adanvo
Fidele Adanvo 2020년 10월 17일
I say the following:
while all PacksA=zeros(1,10)<B and all the values of PacksA updated in #code
exemple
PacksA=[0 0 0 0]
j=1;
B=10
while PacksA(1,j)<B
j=j+1;
if j>4
break
end
#instruction
PacksA(1,j)=PacksA(1,j)+2 % re-compare this updated value of A together with the next value of vector PacksA. exemple While PacksA(1,1)<B (updated) && PacksA(1,2)<B (next value of PacksA )
in another word in each comparison enter a next new value of the vector PacksA together with the values of PacksA(1,j) were updated and have not left the loop.
end

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

답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by