How to save a huge matrix efficiently?
조회 수: 27 (최근 30일)
이전 댓글 표시
Hello,
I want to save a huge matrix into a mat.file.
V = zeros(2000,2000,2000,'uint8');
loop filling the matrix;
save('test.mat','V','-v7.3');
clear all
This works very well! Then I want to get some parts of the variable V in the mat file.
data = matfile('test.mat');
V = data.V(:,:,1); % very slow ~20sec
V = data.V(:,1,:); % very slow ~20sec
V = data.V(1,:,:); % very slow ~20sec
V = data.V(1:500,1:500,1:500); % very fast although more bytes are extracted?! ~ 2sec
So now my question: Is there a possibility to save the matrix in an efficient way to get the slices faster? I already have some huge mat-files, where I can get slices of the volume very fast. This mat-files have the same properties like mine. They are a download, so I have no idea of the making. What I know is the structure of the variable and the type of saving (2182x2182x2242 uint8 and -v7.3). So I guess, it's possible to save the matrix elements in a more efficient way.
I hope you can help me. Best regards and thank you in anticipation!
PS: Why I need that? I'd seen, that normaly it is very fast to get a part of the matfile. So I can reduce working memory. Unfortunately I need this high resolution.
댓글 수: 1
Walter Roberson
2016년 11월 27일
On my system I was able to create a 2000 by 2000 by 2000 uint8 matrix, barely. But saving it with save() was just toooo slow and I had to give it up.
답변 (1개)
Daniel kiracofe
2016년 11월 27일
If you have enough memory and are using a 64 bit version of matlab, using load() to load the entire matrix into memory will be quicker. it will take some time to load the file, but after that each slice will be quicker.
If the matrices are sparse (i.e. they contain mostly zeros with a few non-zero values) then saving the file as a sparse matrix would be significantly quicker (https://www.mathworks.com/help/matlab/ref/sparse.html)
Beyond that, I don't really know any way to make matfile() run quicker. In order to get the slices, matfile() basically has to read the entire file. And that's just going to be slow because the file is big.
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!