Why do I receive an 'Out of Memory' error using FREAD function when my file is smaller than the largest contiguous memory block?

4 views (last 30 days)
I have a large binary file of uint16 data named fname. It smaller than the largest free memory block. When I execute the following commands:
fid=fopen('fname');
F=fread(fid,'uint16')
I receive the following result:
??? Error using ===> fread.
Out of memory. Type HELP MEMORY for your options

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Here, the 'uint16' refers to how to interpret the data in the file and not how to represent it in MATLAB. Thus, class(F) will return double, so the FILESIZE * sizeof(double)/sizeof(uint16) will be larger than the memory block and out of memory error is expected.
To work around this issue, use the 'uint16=>uint16' option to FREAD to make MATLAB interpret the data as uint16 and also store it in MATLAB as uint16. This can be done using either of the following commands
1. F = fread(fid,'uint16=>uint16');
2. F = fread(fid,'*uint16');

More Answers (0)

Products


Release

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!