Wihle loop not running

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 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by