Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I optimize binary file reading in Matlab?

Posted on 2009-04-01
3
Medium Priority
?
1,029 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 2000 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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.
Starting up a Project
Suggested Courses

824 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