Solved

How can I optimize binary file reading in Matlab?

Posted on 2009-04-01
3
938 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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

771 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

10 Experts available now in Live!

Get 1:1 Help Now