while 1 and fget1 loop.

151 ビュー (過去 30 日間)
sermet
sermet 2015 年 1 月 22 日
コメント済み: Ozan Akyildiz 2019 年 2 月 12 日
fide = fopen('data.13o')
head_lines = 0
while 1
head_lines = head_lines+1
line = fgetl(fide)
answer = findstr(line,'END OF HEADER')
if ~isempty(answer), break; end
end
% the header of the data.13o file is;
OBSERVATION DATA M RINEX VERSION / TYPE
LEICA GEO OFFICE 5.0 10-5-13 10:45 PGM / RUN BY / DATE
OBSERVER / AGENCY
O2930689 MARKER NAME
O2930689 MARKER NUMBER
P8UO0W21QTC -Unknown- -Unknown- REC # / TYPE / VERS
-Unknown- TPSGR3 NONE ANT # / TYPE
4303634.7047 2746069.9471 3812585.4149 APPROX POSITION XYZ
1.3289 0.0000 0.0000 ANTENNA: DELTA H/E/N
L1PhaOff: 0.2338 L2PhaOff: 0.2252 COMMENT
1 1 WAVELENGTH FACT L1/2
7 C1 P1 L1 D1 P2 L2 D2 # / TYPES OF OBSERV
2013 4 13 4 56 30.000000 TIME OF FIRST OBS
2013 4 13 7 59 0.000000 TIME OF LAST OBS
16 LEAP SECONDS
27 # OF SATELLITES
END OF HEADER
%this loop works what it supposed to be but I couldn't understand how "while 1" works for this loop and what's the difference between "while 1" and while for the loop.

採用された回答

Guillaume
Guillaume 2015 年 1 月 22 日
while 1 is the same as while true. It means loop forever. The only way to stop the loop is to use a break statement, which is what you're doing with the
if ~isempty(answer), break; end
Another way to write the loop would have been:
answer = '~'; %anything not empty so the loop starts
while ~isempty(answer)
head_lines = head_lines+1
line = fgetl(fide)
answer = findstr(line,'END OF HEADER')
end
  3 件のコメント
Ozan Akyildiz
Ozan Akyildiz 2019 年 2 月 12 日
@Guillame, I think stating that 0 resolves to false and any other number (or char) will resolve to true is enough. No need to berate.

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by