Extract sentences of a specific pattern
Mostrar comentarios más antiguos
I have opened an ascii file using the following code
fid=fopen('test.asc','r');
s = '';
while ~feof(fid)
line = fgetl(fid);
s = strvcat(s,line);
end
Now the file contains sentences of the following pattern:
after slot 16: adjust slottime 1.73149698229 side_stiffness 208.220358294
after slot 32: adjust slottime 1.28516669432 side_stiffness 215.966524494
after slot 48: adjust slottime 1.0 side_stiffness 241.34853159
What is the best way to extract all the sentences of this format.
Thanks
Respuestas (2)
per isakson
el 20 de Jun. de 2012
Try
str = 'after slot 16: adjust slottime 1.73149698229 side_stiffness 208.220358294';
ptn = '^after slot \d+: adjust slottime [\d\.]+ side_stiffness [\d\.]+$';
ii = regexp( str, ptn, 'start' );
not( isempty( ii ) )
.
--- Cont. ---
I have coy&pasted the your three lines to cssm.asc. Try run
str = cssm(();
If that doesn't work try to modify the pattern, ptn, to match the lines in your real file.
function str = cssm
fid = fopen( 'cssm.asc', 'r' );
cac = cell(0);
ptn = '^after slot \d+: adjust slottime [\d\.]+ side_stiffness [\d\.]+$';
while ~feof( fid )
line = fgetl( fid );
if not( isempty( regexp( line, ptn, 'start' ) ) )
cac = cat( 1, cac, {line} );
end
end
fclose( fid );
str = char( cac );
end
1 comentario
Priya Narayanan
el 20 de Jun. de 2012
Priya Narayanan
el 20 de Jun. de 2012
1 comentario
per isakson
el 20 de Jun. de 2012
I cannot interpret this dump.
Categorías
Más información sobre UMTS Test and Measurement 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!