fscanf and fgetl refuses to read my .txt file????

4 views (last 30 days)
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
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
Callum Godfrey
Callum Godfrey on 9 Dec 2020
I have found the issue, doesn't make much sense, but I had the file directory wrong for the script, as when I made a new script and copied everything in it failed to open the file, but somehow the other script could open the file without actually knowing where the file was which I find abit odd.
I also feel like an idiot for not double checking if it was in the right directory in the first place like my other scripts are.

Sign in to comment.

Answers (0)

Categories

Find more on Text Data Preparation in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!