Solved

reading files in matlab into arrays

Posted on 2014-04-25
1
360 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 500 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 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