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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!