fscanf and fgetl refuses to read my .txt file????
4 views (last 30 days)
Show older comments
I have to use fscanf to read a text file into matlab, but for some reason it won't be read in. There are no error codes, it just will not read any of the data inside. I have made my own test files to be read in by the same code and it works, but with this text file it refuses to be read. The text file was originally an .xls file converted into a .txt file if that makes any difference. I am completely stumped.
Heres the code:
r=0;
x=0;
carID = fopen('car_data.txt','rt');
carRaw = fscanf(carID,'%s %f', [9 inf]);
frewind(carID);
while(x~=(-1))
x=fgetl(carID);
r=r+1;
end
r = r-1;
disp(['Number of rows = ' num2str(r)])
fclose(carID);
9 Comments
Walter Roberson
on 9 Dec 2020
filename = 'car_data.txt';
dinfo = dir(filename);
dinfo.bytes
fileattrib(filename)
will tell you how large the file is on disk, and tell you about its file permissions
Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!