Problem in opening and Reading a Binarydata file ??

1 visualización (últimos 30 días)
% 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

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Ag. de 2020
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

Más respuestas (1)

Mario Malic
Mario Malic el 1 de Ag. de 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 comentarios
Mario Malic
Mario Malic el 1 de Ag. de 2020
Editada: Mario Malic el 1 de Ag. de 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
Suvvi Kuppur Narayana Swamy el 1 de Ag. de 2020
Okay ! Thank you so much for your help.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by