if Statement for text files

3 ビュー (過去 30 日間)
Juan Rosado
Juan Rosado 2012 年 7 月 10 日
Greetings,
I have this cell array that displays this text:
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz725.txt','Water_Coastal_Southern_Puerto_Rico_Out.txt'); % URL from forecast web page
fid=fopen('Water_Coastal_Southern_Puerto_Rico_Out.txt');
y=fgetl(fid);
data = textscan( fid, '%s', 'Delimiter', ''); %read the entire file as strings, one per line.
fclose(fid);
out = regexprep( data{1}, '<[^>]+>', '' ) %remove the HTML
n=length(out);
out =
'CWFSJU'
'COASTAL WATERS FORECAST'
'NATIONAL WEATHER SERVICE SAN JUAN PR'
'1024 PM AST MON JUL 9 2012'
'PUERTO RICO AND U.S. VIRGIN ISLANDS WATERS'
''
'AMZ725-101500-'
'COASTAL WATERS OF SOUTHERN USVI VIEQUES AND EASTERN PUERTO RICO OUT'
'10 NM-'
'1024 PM AST MON JUL 9 2012'
'REST OF TONIGHT'
'EAST WINDS 12 TO 16 KNOTS. SEAS 3 TO 4 FEET.'
'ISOLATED SHOWERS. '
'TUESDAY'
'EAST WINDS 12 TO 16 KNOTS. SEAS 3 TO 4 FEET. HAZE.'
'ISOLATED SHOWERS. '
'TUESDAY NIGHT'
'EAST NORTHEAST WINDS 13 TO 16 KNOTS. SEAS 3 TO'
'4 FEET. HAZE. ISOLATED SHOWERS. '
'WEDNESDAY'
'EAST NORTHEAST WINDS 12 TO 15 KNOTS. SEAS 3 TO 4 FEET.'
'HAZE. ISOLATED SHOWERS. '
'WEDNESDAY NIGHT'
'EAST NORTHEAST WINDS 12 TO 15 KNOTS. SEAS 3 TO'
'4 FEET. HAZE IN THE EVENING. SCATTERED SHOWERS THROUGH THE NIGHT. '
'THURSDAY'
'EAST WINDS 8 TO 13 KNOTS. SEAS 2 TO 4 FEET. ISOLATED'
'SHOWERS. '
'FRIDAY'
'EAST SOUTHEAST WINDS 11 TO 16 KNOTS. SEAS 3 TO 5 FEET.'
'ISOLATED SHOWERS. '
'SATURDAY'
'EAST WINDS 13 TO 18 KNOTS. SEAS 4 TO 6 FEET. ISOLATED'
'SHOWERS. '
[1x165 char]
I want to generate an "if" statement that takes certain lines to display it on the Command Window. For example,
if (the text line starts with 'REST... display the lines:
'REST OF TONIGHT'
'EAST WINDS 12 TO 16 KNOTS. SEAS 3 TO 4 FEET.'
'ISOLATED SHOWERS.'
Thank you for your time.
JJR
  3 件のコメント
Juan Rosado
Juan Rosado 2012 年 7 月 10 日
Jan, my humble apologies. Thank you for the pointer, it won't happen again.
Jan
Jan 2012 年 7 月 15 日
編集済み: Jan 2012 年 7 月 15 日
Dear Juan, there is no reason for apologies. Simply edit the question and format the code. This does not help me, but it improves your chances to get a useful answer.
Or you could wait until Walter formats your code. Thanks, Walter!

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

採用された回答

Jan
Jan 2012 年 7 月 10 日
index = find(strncmpi(out, 'Rest', 4));
fprintf('%s\n', out{index + 1});

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2012 年 7 月 10 日
編集済み: Andrei Bobrov 2012 年 7 月 10 日
[S,S] = weekday(now + (0:6),'long')
i1 = strncmp(out,'REST',4)
idx = i1 | ismember(out,cellstr(upper(S)));
I = cumsum(idx);
out2 = out(I(i1) == I);
or
[S,S] = weekday(now + (0:6),'long')
i1 = find(strncmp(out,'REST',4));
i2 = find(ismember(out,cellstr(upper(S))));
out3 = out(i1:i2(find(i1 < i2,1,'first'))-1);

カテゴリ

Help Center および File ExchangeOceanography and Hydrology についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by