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 个)
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!