Q:

How to rearrange matrix column into block using for loop?

I am working on a project where i have used a image whose size is (512x512)then i have divided the whole image by 8 so that there will be 64x64 block then i have rearranged each 8x8 image patch into a single column and my new size is 64x4069.
Now i want to get back the original size i.e 512x512,please help me how to get back it using for loop instead of 'col2im'
a=imread('lena.png');
b=double(a);
[m,n] = size(b);
bl=8;
br=m/bl;
bc=n/bl;
out = zeros(size(reshape(b,bl*bl,[])));
count = 1;
for i = 1:br
    for j= 1:bc
        block = b((j-1)*bl + 1:(j-1)*bl + bl, (i-1)*bl + 1:(i-1)*bl + bl);
        out(:,count) = block(:);
        count = count + 1;
    end
end

A:

This is basically your script written backwards. Some assumptions have to be made, because not every rectangular matrix can arise from the process you  described, and also because the dimensions of the original matrix cannot be uniquely determined from the set of blocks. So, I assume that the original matrix was a square one, and the blocks were squares as well. 
By the way, in your code you use j in the formula for row indices and i for columns; I assumed this was a mistake, and amended it below. 
out = kron((0:3)', 1:16);   % for testing; you would have a 64x4096 matrix here
[m,n] = size(out);
osize = sqrt(n*m); 
bl = sqrt(m);
br = osize/bl;
bc = br;
original = zeros(osize);
count = 1;
for i = 1:br
    for j = 1:bc
        block = zeros(bl);
        block(:) = out(:,count);
        original(1+(i-1)*bl : i*bl, 1+(j-1)*bl : j*bl) = block;
        count = count + 1;
    end
end

Input for testing: 
 0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
 1     2     3     4     5     6     7     8     9    10    11    12    13    14    15    16
 2     4     6     8    10    12    14    16    18    20    22    24    26    28    30    32
 3     6     9    12    15    18    21    24    27    30    33    36    39    42    45    48

Output:
 0     2     0     4     0     6     0     8
 1     3     2     6     3     9     4    12
 0    10     0    12     0    14     0    16
 5    15     6    18     7    21     8    24
 0    18     0    20     0    22     0    24
 9    27    10    30    11    33    12    36
 0    26     0    28     0    30     0    32
13    39    14    42    15    45    16    48

