Filter löschen
Filter löschen

while loop in data file for trapz?

1 Ansicht (letzte 30 Tage)
John
John am 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
disp(Num)
end
doesn't work. Any help?

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by