how to use for loop ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
pruth
el 24 de Nov. de 2017
Respondida: pruth
el 26 de Nov. de 2017
one of my friend help me to write this code to read one text file which works perfect. but now I want to use this code to process multiple text files from one same folder. I am attaching 3 files for example. I am not able to use perfect loop for all these files.
content = fileread( 'L3_tropo_ozone_column_apr14.txt' ) ;
filename = char('L3_tropo_ozone_column_apr14.txt')
% - Remove first space on all data rows.
content = regexprep( content, '(?<=[\r\n]) ', '' ) ;
% - Split by "lat = ..." separator.
blocks = regexp( content, '\s+lat[^\r\n]+', 'split' ) ;
% - Extract header from block 1.
pos = regexp( blocks{1}, '\)\s+\d', 'start' ) ;
header = blocks{1}(1:pos) ;
blocks{1} = blocks{1}(pos+1:end) ;
% - Merge blocks, remove \r\n, replace spaces by 0s.
blocks = [blocks{:}] ;
blocks = regexprep( blocks, '[\r\n]', '' ) ;
blocks(blocks == ' ') = '0' ;
% - Convert to 120x288 numeric array.
data = reshape( sscanf( blocks, '%3d' ), 288, 120 ).' ;
1 comentario
Stephen23
el 24 de Nov. de 2017
This is explained quite well in the MATLAB documentation:
and a thousand times on this forum:
Respuesta aceptada
Más respuestas (1)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!