Invalid file identifier. Use fopen to generate a valid file identifier.

I'm trying to open a file in this function, for the purpose of using it in another function. However, when I call on it, it gives me the error in fread, as stated in the title. I believe this is a result of fopen failing to open the file. However, I'm not certain how to fix it. Any help is appreciated. Thank you.
fileID = fopen(filename, 'rt');
[A,count]= fread(fileID,[2 inf], 'uint8');

4 Comments

Did you check to make sure that filename is a valid file name and the filepath is included in it and/or matlab can find the file? Most errors with fread as you stated in the title occur in this way when Matlab can't find the file for whatever reason.
Please show us the displayed message:
[fileID,msg] = fopen(filename, 'rt');
assert(fileID>=3,msg)
the file name is PMHFIB_ORIGINAL.ATT. Is this file name invalid?
and I added the path below to the file in question, but I still recieved the same error.
addpath /Users/kira/desktop/PHYS4115Tables/'att';
Also, when i use teh code given to me by Stephen, it gives me the message: "no such file or directory".
What does this mean?

Sign in to comment.

Answers (1)

Try
filespec = fullfile( "/Users/kira/desktop/PHYS4115Tables/'att'", filename );
fileID = fopen(filespec, 'rt');
assert(fileID>=3,msg)
And show us the displayed message.
What's 'att' ? The name of a subfolder?

Products

Release

R2017b

Tags

Asked:

on 5 Nov 2019

Answered:

on 19 Nov 2019

Community Treasure Hunt

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

Start Hunting!