?
Solved

reading files in matlab into arrays

Posted on 2014-04-25
1
Medium Priority
?
394 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
[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
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

801 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