Borrar filtros
Borrar filtros

How to read a data from txt file: only a specific part of txt

7 visualizaciones (últimos 30 días)
serhat tekebas
serhat tekebas el 13 de Jun. de 2018
Comentada: Paolo el 14 de Jun. de 2018
Hi; I have a txt file as above.I want to get the value from marked section of txt and assign it to a variable.
  4 comentarios
Paolo
Paolo el 13 de Jun. de 2018
Please attach the text file and not the screenshot.

Iniciar sesión para comentar.

Respuesta aceptada

Paolo
Paolo el 13 de Jun. de 2018
You can use regexp to match the sampling value. The expression below assumes that the character "E" is followed by a "-" character.
text = fileread('20171109_144634_14306_6O61N2.txt');
[match] = regexp(text,'(\d*\.\d*E-\d*)','match');
sampling = str2double(match{1});
sampling =
0.0050
  7 comentarios
serhat tekebas
serhat tekebas el 14 de Jun. de 2018
what is the difference between your solution and
text = fileread('20171109_144634_14306_6O61N2.txt');
timevar=text(191:203)
Paolo
Paolo el 14 de Jun. de 2018
@serhat
If for some reason your time information changes position in the text file, text(191:203) will fail to extract that information. The regex pattern will find the data anywhere in the file.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by