read file txt with strings and numbers

8 visualizaciones (últimos 30 días)
Khoder Makkawi
Khoder Makkawi el 11 de Sept. de 2023
Comentada: Star Strider el 11 de Sept. de 2023
blablabla
aaa 10 test 20
bbb 11 test1 21
ccc 12 test2 22
I have this data in a file .txt and I want to read the file.
I tried the following code but it is not working as I want to:
fid = fopen('test','r');
testData = fscanf(fid, '%s %d %s %d',[2 inf]);
fclose(fid);

Respuesta aceptada

Star Strider
Star Strider el 11 de Sept. de 2023
Use readtable or readcell, depending on what you want. There are other options (textscan), however those two are easiest to use and will likely do what you want.
Consider using the 'HeaderLines' name-value pair with readtable.
  2 comentarios
Khoder Makkawi
Khoder Makkawi el 11 de Sept. de 2023
it doesn't work because there is the first line that I don't want to read it.
How I can skip it ?
I used fscanf because I saw that I can start by the number of line I want
Star Strider
Star Strider el 11 de Sept. de 2023
How I can skip it ?
And I quote from, my original Answer:
Consider using the 'HeaderLines' name-value pair with readtable.
.

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

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by