if Statement for text files
Mostrar comentarios más antiguos
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 comentarios
Jan
el 10 de Jul. de 2012
Please read the instruction about formatting code in the forum again. E.g. the "About Matlab Answers" is a good point to start from. A forum is more attractive, when the users follow the rules and standards.
Juan Rosado
el 10 de Jul. de 2012
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 10 de Jul. de 2012
Editada: Andrei Bobrov
el 10 de Jul. de 2012
[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);
Categorías
Más información sobre Oceanography and Hydrology en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!