% Here is the code for opening the and reading the data file
file='dspCW2datav2.bin';
fid=fopen(file,'r'); %%%%%% fid= -1 ????
format='double';
data=fread(fid,format);% Reading the binary data in the matlab
So , every time running this , i get an error for using fread . But i now figured out that's happening because fid = -1 , hence this is leading to error in fread .
The error is as follows!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in suvvi_20201366 (line 21)
data=fread(fid,format);% Reading the binary data in the matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can someone please help me in getting rid of this error ????
Thankyou,
suvvi

 채택된 답변

Image Analyst
Image Analyst 2020년 8월 1일

0 개 추천

The file does not exist or exists in an area that you're not allowed to see. Try this
% Here is the code for opening the and reading the data file
fileName = 'dspCW2datav2.bin';
fid=fopen(fileName, 'r'); %%%%%% fid= -1 ????
if fid == -1
errorMessage = sprintf('You are not allowed to open %s.\nIt was not found on the search path.', fileName);
uiwait(errordlg(errorMessage));
return;
end
format='double';
data=fread(fid,format);% Reading the binary data in the matlab

추가 답변 (1개)

Mario Malic
Mario Malic 2020년 8월 1일

0 개 추천

fileID = fopen('dspCW2datav2.bin');
A = fread(fileID)
Never tried opening bin files, but this should be working. Function fread does not accept the "format" variable, as you can see from documentation.

댓글 수: 8

No its not working .fileID still is -1 . Im sure as long as it opens as -1 , there will error.
i have no idea how to work this out !
Thank you anyways.
What might be happening is that data is [1x1] and it only accepts one value. -1 is value that denotes end of file, so, probably it has read all the characters from the file with the last one being the -1.
May be , that could be the case.
But i dont understand why there is an error occuring at fread ??
Upload the file.
Sorry , i tried uploading but im not able to as this .bin format is not supported here.
Mario Malic
Mario Malic 2020년 8월 1일
편집: Mario Malic 2020년 8월 1일
Your file might not be good, as I downloaded some random bin file from internet and used commands above and it worked. Search for similar topics.
Okay ! Thank you so much for your help.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터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!

Translated by