필터 지우기
필터 지우기

How to open a binary file that returns -1 when using fopen?

조회 수: 3 (최근 30일)
Cristina
Cristina 2017년 4월 29일
댓글: Walter Roberson 2017년 4월 29일
I am trying to open a file that someone else recorded. The file is supposedly binary. The extension is meaningless (it refers to the content of the file...). I tried using fopen and the file identifier is -1 (so can't read it in). If I 'manually' open the file it does not show as binary but as many symbols. How can I approach this?
Thank you

답변 (2개)

Walter Roberson
Walter Roberson 2017년 4월 29일
Use
filename = 'NameOfBinaryFile';
[fid, msg] = fopen(filename, 'r');
if fid < 0
error('Could not open file "%s" because: "%s"', filename, msg);
end
For example it might be in use by another program, or you might not have permission to read it.
  댓글 수: 2
Cristina
Cristina 2017년 4월 29일
I am not trying to make my program available to others. I am trying to analyse the data that is stored in the binary file. The binary data seems to be converted into characters if I open the file with an editor, and the file can't be open at all in MATLAB. I am trying to access the binary data.
Walter Roberson
Walter Roberson 2017년 4월 29일
Currently you do not know why the fopen fails. The above code will tell you why. It has nothing to do with making your program available to others: it has to do with debugging a problem with your program or configuration.

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


Image Analyst
Image Analyst 2017년 4월 29일
Check the file attributes. If it's marked at readonly and you're trying to open it for writing, it might return -1. Make sure the readonly checkbox is not checked.

카테고리

Help CenterFile 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