Problem in opening and Reading a Binarydata file ??
Show older comments
% 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
Accepted Answer
More Answers (1)
Mario Malic
on 1 Aug 2020
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 Comments
Suvvi Kuppur Narayana Swamy
on 1 Aug 2020
Mario Malic
on 1 Aug 2020
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.
Suvvi Kuppur Narayana Swamy
on 1 Aug 2020
Suvvi Kuppur Narayana Swamy
on 1 Aug 2020
Mario Malic
on 1 Aug 2020
Upload the file.
Suvvi Kuppur Narayana Swamy
on 1 Aug 2020
Mario Malic
on 1 Aug 2020
Edited: Mario Malic
on 1 Aug 2020
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.
Suvvi Kuppur Narayana Swamy
on 1 Aug 2020
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) 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!