while loop in data file for trapz?

I have an array (read in from a data file) and I'm trying to integrate a series of values in one column. The problem is that sometimes there are 6, 7, or 8 values in the series to integrate. These, however, are defined by a 'Number' at the beginning of each row. So, it seems: while Number == some value, then I can identify the range of values over which to do the integration. But matlab doesn't recognize any variables inside the loop. Even
A = [Num X Y Z];
while Num == 1
disp(Num)
end
doesn't work. Any help?

回答(1 个)

Apparently, the variable (Num) is not (1). That's why the (while loop) returns nothing. I've tried the lines you posted and it works when Num==1, perfectly. So perhaps you meant to code:
A = [Num X Y Z];
while Num ~= 1 % Works when Num equals NOT 1
disp(Num)
end
.. or perhaps you meant
while A(1)==1
?? Also keep in mind that the while loop such as the one programmed above will never stop by itself, unless there is some calculation inside the loop that changes the value of Num.

1 个评论

Yes, thanks. I had finally realized I needed a counter inside the loop. I appreciate the response; very helpful.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

标签

提问:

2013-4-13

Community Treasure Hunt

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

Start Hunting!

Translated by