while loop in data file for trapz?

2 views (last 30 days)
John on 13 Apr 2013
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
doesn't work. Any help?

Answers (1)

Ahmed A. Selman
Ahmed A. Selman on 14 Apr 2013
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
.. 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 Comment
John on 14 Apr 2013
Yes, thanks. I had finally realized I needed a counter inside the loop. I appreciate the response; very helpful.

Sign in to comment.



Community Treasure Hunt

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

Start Hunting!