Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2455

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

I'm trying to read a sequence of files with textscan, but I keep getting this error:

Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.

My code is:

fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'rt');
line = textscan(fd, '%s %f %d %f %f %f %f %f %f %f %f %f %f %f %f');

When I try to see the output of ['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name] it returns the path correctly:

D:\Thesis\Data\vedai_co_75_25\train\labels\00000000.png

Also command fopen(D:\Thesis\Data\vedai_co_75_25\train\labels\00000000.png) returns 3 or 4 or etc.

But command fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name]) returns -1.

How can I make this work?

Upvotes: 0

Views: 3793

Answers (1)

Richard
Richard

Reputation: 1060

The problem might be that you are trying to open a .png file in text mode.
Try fd = fopen( file_name, 'r'), or in your example:

fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'r');

On Windows, opening the wrong files in text mode can cause issues. The help of fopen states:

(On Unix, text and binary mode are the same, so this has no effect. On PC systems this is critical.)

Upvotes: 2

Related Questions