Reading Text file in matlab
Afficher commentaires plus anciens
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?
Réponses (2)
Image Analyst
le 11 Nov 2017
Don't even use ReadTestData(). Try this in your main program:
fullFileName = fullfile(pwd, 'TestData.tst')
t = readtable(fullFileName)
Star Strider
le 11 Nov 2017
0 votes
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!