Error using fseek Invalid file identifier. Use fopen to generate a valid file identifier.
2 views (last 30 days)
Show older comments
Anybody knows why it comes up with this error at I = dicomread(fullFileName); line?
Here is my code:
filePatternu = fullfile(myFolder, 'test*.dcm*'); allFilesi = dir(filePatternu);
for k= 1: length(allFilesi) baseFileName = allFilesi(k).name; % e.g. "1.png" fullFileName = fullfile(myFolder, baseFileName); I = dicomread(fullFileName); end
0 Comments
Accepted Answer
Jan
on 2 May 2018
After formatting (using the "{} Code" button...), your code looks fine:
filePatternu = fullfile(myFolder, 'test*.dcm*');
allFilesi = dir(filePatternu);
for k = 1:length(allFilesi)
baseFileName = allFilesi(k).name; % e.g. "1.png"
fullFileName = fullfile(myFolder, baseFileName);
I = dicomread(fullFileName);
end
The only problem I can see is that this catches folders also, when their name match the ".dcm*" pattern. Try this:
allFilesi = dir(filePatternu);
allFilesi([allFilesi.isdir]) = [];
Catching the problem is a good idea also:
for k = 1:length(allFilesi)
baseFileName = allFilesi(k).name; % e.g. "1.png"
fullFileName = fullfile(myFolder, baseFileName);
try
I = dicomread(fullFileName);
catch ME
error('Forum:My:Function', 'Failed to import file [%s]: %s', ...
fullFileName, ME.message);
end
end
Now you can see for which file the import is failing.
Another idea is that the file is used or removed by another application between the dir and the dicomread. Displaying the failing file will help you to identify the problem.
0 Comments
More Answers (0)
See Also
Categories
Find more on Convert Image Type 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!