Solved

How can I optimize binary file reading in Matlab?

Posted on 2009-04-01
3
954 Views
Last Modified: 2016-02-10
As I explained in my last question ( http://www.experts-exchange.com/Programming/Languages/MatLab/Q_24268148.html , thanks yuk99 for the help), I developed a function to read a binary raw data file in Matlab.

Each data sample is stored in the file in 2 bytes, it ranges from 0 to 4095 (12 bits).
In the 2 bytes corresponding to a data sample, the upper 4 bits contain an annotation information, and the 12 other bits contain the data sample.

My code works fine for files with small size, but I need to read a file with a size of about 500 Mb, and following error occurs:

 ??? Error using ==> fread
 Out of memory. Type HELP MEMORY for your options.

Could someone help me optimize my code to avoid this error?
fid=fopen(FILENAME,'r','ieee-le');
 

% Read all 2 bytes samples in 16 bits integers and retransform values in binary

A2=dec2bin(fread(fid,inf,'uint16','ieee-le'),16);
 

% Close file

fclose(fid);
 

% Create an array containing the 12 bits of data

sample=bin2dec(A2(:,5:16));

Open in new window

0
Comment
Question by:JulienVan
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
yuk99 earned 500 total points
ID: 24039071
This is common problem in Matlab. Read this doc, it may give you some ideas.
http://www.mathworks.com/support/tech-notes/1100/1106.html
0
 
LVL 15

Assisted Solution

by:yuk99
yuk99 earned 500 total points
ID: 24039095
Can you actually upgrade? Working with uints will save you some memory.

Another useful doc: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/brh72ex-25.html
0
 
LVL 9

Expert Comment

by:masheik
ID: 24078049
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse Neon start with Admin account only 6 92
Device same like our heart 12 77
Programatically extract date from website 8 67
Plain Text Editor for iPad 6 60
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now