Getting "out of memory" while in for loop in huge matrix

Hi there
So I have a 64x65536 matrix in which I want to extract the first 1:9 coefficients of each row, in other words, I want a 9x65536.
To do that I wrote the following code:
coefT1a9 = zeros(9,65536);
k=1;
for i=0:1:65536
for j=0:1:8
coefT1a9(k,:) = Tzig(j+1,i+1);
k=k+1;
end
k=1;
end
Tzig is the 64x65536 matrix. When I compile the code, I'm getting out of memory, or a really long processing time. I can't understand what am I doing wrong.
If you're wondering what the goal is, basically I have a zigzag matrix with DCT coefficients from an image and I want to take out specific coefficients from a 8x8 block (64 coefficients per block). The first one is the DC coefficient, wich I got, then 1-9, 10-35 and finally 36-63.
Thanks for your help!

 Accepted Answer

testMatrix=randi(50,64,65536);
%Extract first 9 row values for each column
extract=testMatrix(1:9,:);
I assume this is what you are trying to do (I was slightly confused by your wording, and I think your code is probably flawed in that you are indexing a single value from each row of your matrix and then assigning that value to all 65536 columns of your co-efficient matrix (repeatedly)

1 Comment

Thank you so much. For some reason I was making it more difficult than it seemed. That solved it. Thumbs up !

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!