I would like to reduce a very long vector without using any (significant amount of) additional memory. For instance, suppose I have slightly over 6GB available and use 6GB of it for a vector A of size [2*N,1]. After some calculations I would like to keep only the first N entries of A. I tried
A = A(1:N, 1);
but it appears that for a short period I will need additional 3GB (which I do not have) as if the first half of A is copied somewhere else and then back. I am looking for a way to move the end-of-array pointer of A to the middle of A and release the second half of A.
Thank you, Borislav
No products are associated with this question.
MATLAB does not provide any explicit way to adjust the sizes.
Your best chance (not guaranteed at all) would be to write an auxillary function,
function A = chopvec(A, N) A = A(1:N); end
MATLAB is able to notice that the input and output array names are the same, and can do some kinds of work "in place" (provided the input array was not a shared one.) I do not know if shortening is one of the things it can do. Possibly not.
Ah.... did you try
A(N+1:end) = ;