Please tell me how to resolve out of memory error of this code
4 views (last 30 days)
Show older comments
shikha gautam
on 6 Jan 2015
Commented: shikha gautam
on 12 Jan 2015
count = 1; j = 1; matrix=[];
while(j+63<m) k = 1; while(k+63<n) dum=zeros(1,64*64); dum(1:(min(m-j+1,64)*(min(n-k+1,64))))=reshape(img1(j:min(j+63,m),k:min(n,k+63)),1,(min(m-j+1,64)*(min(n-k+1,64)))); matrix = [matrix;j,k,dum]; count = count+1; k = k+1; end j = j+1; end
0 Comments
Accepted Answer
Titus Edelhofer
on 6 Jan 2015
Hi,
assuming that the out of memory happens in the assignment
matrix = [matrix; j,k,dum];
I would suggest to preallocate matrix. Compute the number of rows matrix will have - something like (m-63)*(n-63) - and preallocate
matrix = zeros((m-63)*(n-63), 2+64*64);
Instead of
matrix = [matrix; j,k,dum];
you write
matrix(count, :) = [j k dum];
If the preallocation works (depends on m, n of course), then the rest should work.
Titus
8 Comments
Titus Edelhofer
on 8 Jan 2015
There is not much I can offer: your result is too large to fit into memory. So you need to rethink if you need to store the result like this? What do you do with it later? You don't do the calculation for fun I guess, so the question is how to proceed without storing all the matrices...
More Answers (0)
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!