x1=0:5; %tank1 capicity
x2=0:10; %tank2 capicity
x3= 0:1000000; %tank3 capicity
y1=2 %L/min pipe 1
y2=1 %L/min pipe 2
y3=0.5 %L/min pipe 3
v1=0 ;
while (v1<5)
v1=x1+y1;
end
why my loop is not running well.I get v1 6 and 7 even when my condition v1 < 5

답변 (1개)

Torsten
Torsten 2023년 2월 10일
편집: Torsten 2023년 2월 10일

0 개 추천

At first (by your setting) v1 = 0. Thus the while loop is entered.
After entering the while loop, v1 becomes x1 + y1 = [2 3 4 5 6 7], an array of numbers.
After this, MATLAB exits the while loop because not all elements of v1 are < 5 (that's what v1 < 5 for a vector means: all elements must be < 5)
Everything as expected.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2023년 2월 10일

편집:

2023년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by