[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

reading files in matlab into arrays

Posted on 2014-04-25
1
Medium Priority
?
419 Views
Last Modified: 2016-03-02
Hi

I have matlab version 2009. When i try to read in a file that has 63174528 floats (ie 252698112 bytes),  I end up with an array that has lesser number of numbers. I understand that matlab treats numbers as doubles i.e. 8 bytes , but even so, I should have plenty of memory to store 63174528 doubles (i.e. 505396224 bytes)

When i run the memory command in matlab to check out my system resources, here is what i get
>memory

Maximum possible array:              28069 MB (2.943e+010 bytes) *
Memory available for all arrays:     28069 MB (2.943e+010 bytes) *
Memory used by MATLAB:                 659 MB (6.915e+008 bytes)
Physical Memory (RAM):               16361 MB (1.716e+010 bytes)

*  Limited by System Memory (physical + swap file) available.


So as you can see, 28069 MB, is plenty of space to accomodate my file of numbers in an array.

my matlab code is as follows:
fid=fopen(filename);
data=fread(fid,'float32');

Here, I get data as <14598144x1 double> array. I am missing some 600,000 numbers.

Can anyone advise as to what can be done to accomodate 63174528 numbers in an array and why the array is so small when the memory command lists far more memory being available.

PS: the file was written out in the following way in C++:
FILE *fp=fopen("myfile.txt","wb");
fwrite((void*)f,sizePerElement,numElements,fp) //dump bytes pointed by a pointer f into the binary file



thanks
0
Comment
Question by:LuckyLucks
1 Comment
 
LVL 15

Accepted Solution

by:
yuk99 earned 2000 total points
ID: 40047629
The problem shouldn't be connected with available memory. It probably related with how the data are organized in the input file.

Can you check if the data recorded into the file in C++ and what you get in MATLAB are the same (well, at least, the first elements)? Are you using the same OS to write and to read the file?
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
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.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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