Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read and write files with contain both ASCII and binary data

Status
Not open for further replies.

chairmantom

Mechanical
Mar 23, 2007
3
I have a file which starts with an ASCII header followed by binary 14-bit data. I wish to use Matlab open the file, convert the binary data to numbers on which some calculations are performed before saving the file. I need to leave the file in the same form as it was originally, i.e. with ASCII header followed by binary 14bit data.

Currently, I can open the file using textscan, and view the headers (while the binary part is nonsense), or I can open using fread, and view the binary data (with the header being nonsense).

I would really appreciate any advice about how to read and write files with contain both ASCII and binary data.

I hope that make some sort of sense.
 
Replies continue below

Recommended for you

Why can't you read everything in as binary and cast the header back into text?

TTFN

Eng-Tips Policies FAQ731-376


 
You can use fread(fid,var,format) with combinations of format as uchar, real*4, etc to pick out the ASCII and binary sections. I even have to deal with the line-feed carriage returns as uchar strings in some of my file reading deals. If you can read the file with a hex editor its pretty easy to spot what sections are ascii and what are binary. Then just paw thru it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor