Borrar filtros
Borrar filtros

Problem while using textscan

1 visualización (últimos 30 días)
Shelender Kumar
Shelender Kumar el 26 de Oct. de 2018
Comentada: Star Strider el 31 de Oct. de 2018
My file has a string as the first row and numeric values as other rows, I can get rid of the header by using formatspec and N as given textscan help. I do not want to write %f four times while using the textscan again to read the numeric data. I have given the test code and please find the sample file. Thanks for helping
filename = 'S.txt'; fileID = fopen(filename); formatSpec = '%s'; N = 4; C_text = textscan(fileID,formatSpec,N); %% Read the numeric data in the file. C_data0 = textscan(fileID,'%f %f %f %f','CollectOutput',1); %% Here I do not want to write %f 4 times

Respuesta aceptada

Star Strider
Star Strider el 26 de Oct. de 2018
Editada: Star Strider el 26 de Oct. de 2018
If you do not want to type the format string, just use the dlmread funciton:
S = dlmread('S.txt', '\t', 1, 0)
S =
1 1 1 1
2 2 2 2
3 2 3 3
There are many ways to read files in MATLAB.
  18 comentarios
Shelender Kumar
Shelender Kumar el 31 de Oct. de 2018
Thanks a lot it helps
Star Strider
Star Strider el 31 de Oct. de 2018
As always, my pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by