Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 68081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:21:38+00:00 2026-05-10T19:21:38+00:00

My knowledge of matlab is merely on a need to know basis, so this

  • 0

My knowledge of matlab is merely on a need to know basis, so this is probably an elementary question. Nevertheless here it comes:

I have got a file containing data (16-bit integers) stored in binary format. How do I read it into a vector /an array in matlab? How do I write this data to a file in matlab? Is there any smart tweak to increase the performance speed when reading/writing a huge amount of data (gigabytes)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:21:39+00:00Added an answer on May 10, 2026 at 7:21 pm

    As Bill the Lizard wrote you can use fread to load the data into a vector. I just want to expand a little on his answer.

    Reading Data

    >> fid=fopen('data.bin','rb') % opens the file for reading >> A = fread(fid, count, 'int16') % reads _count_ elements and stores them in A. 

    The commands fopen and fread default to Little-endian[1] encoding for the integers. If your file is Big-endian encoded you will need to change the fread to

    >> A = fread(fid, count, 'int16', 'ieee-be'); 

    Also, if you want to read the whole file set

    >> count=inf; 

    and if you want to read the data into matrix with n columns use

    >> count=[n inf]; 

    Writing Data

    As for witting the data to a file. The command, fwrite, in Bill’s answer will write to a binary file. If you want to write the data to a text file you can use dlmwrite

    >> dlmwrite('data.csv',A,','); 

    References

    [1] http://en.wikipedia.org/wiki/Endianness

    Update

    1. The machine format (IE, ieee-be, ieee-le, vaxd etc.) of the binary data can be specified in either the fopen or the fread commands in Matlab. Details of the supported machine format can be found in Matlab’s documentation of fopen.

    2. Scott French’s comment to Bill’s answer suggests reading the data into an int16 variable. To do this use

      >> A = int16(fread(fid,count,precision,machineFormat)); 

      where count is the size/shape of the data to be read, precision is the data format, and machineformat is the encoding of each byte.

    3. See commands fseek to move around the file. For example,

      >> fseek(fid,0,'bof'); 

      will rewind the file to the beginning where bof stands for beginning of file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Really dumb 'workaround', and I'm sure it'll get downvoted, but… May 11, 2026 at 2:17 pm
  • added an answer You need to also check for '\r\n' and '\r', as… May 11, 2026 at 2:17 pm
  • added an answer You can call the LockFile Windows API function through the… May 11, 2026 at 2:17 pm

Related Questions

Apologies if any of what I'm about to say makes no sense or overlooks
I get to dust off my VBScript hat and write some classic ASP to
This isn't my code; I am trying to figure out what exactly this does.
I'm in need of help - I've got two mysql databases on different servers

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.