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
Solved

How can I optimize binary file reading in Matlab?

Posted on 2009-04-01
3
980 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

829 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