Error using fseek - while running the matlab code. Input to the program looks fine.
古いコメントを表示
Error using fseek
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in dicom_getFileDetails>getFileLength (line 33)
fseek(fid, 0, 'eof');
Error in dicom_getFileDetails (line 21)
details.bytes = getFileLength(fid);
Error in dicominfo (line 51)
fileDetails = dicom_getFileDetails(filename);
Error in Generate_RS_Object_DICOM (line 3)
rr = dicominfo(stfile,'UseVRHeuristic',false); % return structure rr
Error in Structure_To_Binary_Mask (line 5)
RS = Generate_RS_Object_DICOM(RSFile);
Error in SIFT_RUN_SET_Thorax_PMB (line 32)
[img1, imgB1L,Pos1,Res1,Dim1,~,~] = Structure_To_Binary_Mask(CTDir1,RSFile1,'LUNL');
4 件のコメント
Walter Roberson
2019 年 5 月 6 日
The file could not be opened. Check whether you need to pass a fully qualified file name as the second argument
Adam Danz
2019 年 5 月 6 日
Assuming you're using fopen(), what's the value of fid?
fid = fopen('yourfile')
Shiba Kuanar
2019 年 5 月 6 日
Adam Danz
2019 年 5 月 7 日
I'm not familiar with some of the functions listed in your error message so I can't give good advice on the solution. fseek() requires a file identifier that is created by fopen(). Instead, you mentioned that you're providing a path to the file. That seems to be causing the error. So at some point you need to produce the fid as I showed in my answer below.
If this is confusing or you need more feedback, please continue the discussion.
回答 (2 件)
Which version of matlab are you using (there's a field on the right at the top of this web page for you to fill in)? From the error message it's not the latest, as the line in dicominfo that produces the error is now line 55. However, it does appear that the subfunctions dicom_getFileDetails and dicom_getFileDetails>getFileLength are identical to yours in 2019a.
Typically, the error you see is caused by a failed fopen but dicom_getFileDetails does check that the file opened successfully before calling fseek, so the fseek should always succeed unless your file system is somehow corrupted or your computer somehow lose access to the file after opening it. (e.g. file on usb drive that is suddenly disconnected). Or possibly your anti-virus interferes.
To help with diagnosis, can you type
dbstop if error
at the command line, run your code and when it breaks into the debugger because of the error, tell us the value of fid.
----- addendum ----
Actually, looking more closely at dicom_getFileDetails, there's a potential for a failed fopen to not be detected. I'll be submitting a bug report to Mathworks.
If the exact file name you supply is not found, the codes tries to find a matching file by adding various extensions (.dcm, .dic, .dicom, .img). If the file exists, the code opens it without checking that the fopen is indeed succesfull. So if you don't specify the extension but the file with extension exists but cannot be opened then you'll see the error you saw. Possible reason for a file to exist but not being able to be opened is that you've got read permission on the directory but not the file.
What is the exact filename you're passing to the function?
Adam Danz
2019 年 5 月 6 日
3 件のコメント
Guillaume
2019 年 5 月 7 日
Note that dicominfo (and all the ancillaries) is a function that is part of matlab. The error does not appear to come from a custom function.
Adam Danz
2019 年 5 月 7 日
I'm assuming the problem starts in Structure_To_Binary_Mask() where the second input (RSFile1) seems to point to a file that is passed to Generate_RS_Object_DICOM() and then perhaps on to dicominfo(). Those first two functions are custom.
My guess is that those custom functions rely on a string that identifies a file and that string is passed forward and eventually causes in error where a file identifier is expected.
Shiba Kuanar
2019 年 5 月 8 日
Thank You all. I am able to move forward. Issue was i was passing multiple files on the parameter.
カテゴリ
ヘルプ センター および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!