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

79 Ansichten (letzte 30 Tage)
this is my pgm
function [filenames, classIDs] = ReadOutexTxt(txtfile)
i= 1;
fid = fopen(txtfile,'r');
%tline = fgetl(fid); % get the number of image samples
while 1
tline = fgetl(fid);
if ~ischar(tline)
break, end
%disp(tline)
index = findstr(tline,'.');
filenames(i) = str2double(tline(1:index-1)); % the picture ID starts from 0, but the index of Matlab array starts from 1
classIDs(i) = str2double(tline(index+5:end));
i = i+1;
end
fclose(fid)

Akzeptierte Antwort

Thorsten
Thorsten am 21 Okt. 2015
Bearbeitet: Thorsten am 21 Okt. 2015
Add
if fid == -1
error('Cannot open file.')
end
You probably misspelled txtfile or it is not in the current directory.

Weitere Antworten (0)

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by