×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

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

TTFN

Eng-Tips Policies FAQ731-376


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

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources