Solved

How can I optimize binary file reading in Matlab?

Posted on 2009-04-01
3
999 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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