Reading Text file in matlab

I believe I am missing something. I am trying to read in a large text file using fscanf.
Here is the code
fileName = 'TestData.tst'
format = '%d%*s%f%f%f%f%%f%f%f%f%f%f%f%f%f%f%f%f%f'
size = [19,Inf]
B = ReadTestData(fileName, format, size)
B = B'
function A = ReadTestData (fileName, format, size)
%fileName = 'TestData.tst'
fileID = fopen(fileName, 'r')
A= fscanf(fileID, format, size)
end
}
The function is in a different file than the main code.
Here is my input file
75 data 2.5 3.1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
4 data 5.5 6.1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
10 data 11 12 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
13 data 14 15 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
It's a simplified version of some aircraft data I have recorded. When I execute the code I only get a 6 by 1 matrix containing only part of the first line in the data file. I've tried this on shorter lines, 4 items long, and it works. What am I missing?

Respuestas (2)

Image Analyst
Image Analyst el 11 de Nov. de 2017

1 voto

Don't even use ReadTestData(). Try this in your main program:
fullFileName = fullfile(pwd, 'TestData.tst')
t = readtable(fullFileName)
Star Strider
Star Strider el 11 de Nov. de 2017

0 votos

I would use the textscan (link) function to read them.

Categorías

Etiquetas

Preguntada:

el 11 de Nov. de 2017

Respondida:

el 11 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by