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

2 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2018-5-2
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 个)

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by