Memmap in MATLAB for huge arrays

I want to create memmapin MATLAB. In python, I could do this:

ut = np.memmap('my_array.mmap', dtype=np.float64, mode='w+', shape=(140000,3504))

Then I use it as a regular array, the OS guaranteed that my memory was never full. How to do it in MATLAB?

From the docs, it seems like I first need to create some array in MATLAB, and then write it to a file and read with memmap!

Matlab docs aren’t clear enough: Please give an example of creating a random size array (140,000.15000) and multiply it by another similar matrix.

+4
source share
2 answers

You must first create an empty file, and then use memmapfile:

size=[140000,3504];
filesize=0;
datatype='float64';
filename='my_array.dat';
fid=fopen(filename,'w+');
max_chunk_size=1000000;
%fills an empty file
while filesize<prod(size)
    to_write=min(prod(size)-filesize,max_chunk_size);
    filesize=filesize+fwrite(f, zeros(to_write,1), datatype);
end   
fclose(fid);
m = memmapfile(filename,'Format','double', 'Writable',true);
+6
source

I think you are looking for a function memmapfile

Example:

m = memmapfile('my_array.dat','Format','double', 'Writable',true)
+2
source

Source: https://habr.com/ru/post/1612159/


All Articles