Read a txt file at a certain position
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmad Alsabbagh
el 3 de Mayo de 2016
Editada: Ahmad Alsabbagh
el 4 de Mayo de 2016
Dear All,
I am trying to write a code that will read a matrix at a certain position in a text file.
For example, the text file will contain the following
Mike Code
This code is helpful
The Values of k is
12
123
23.4
1234
184.2
I want the code to read the values of k. Thus, I want the code to search for the line "The Values of k is" and start taking the numbers from the following lines. (I don't know the line number)
Thanks
0 comentarios
Respuesta aceptada
Walter Roberson
el 4 de Mayo de 2016
filecontent = fileread('YourFile.txt');
filecontent = regexprep(filecontent, '.*The Values of k is\s*','');
data = sscanf(filecontent, '%f');
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing 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!