Updated solution based on the answer below:
This solution takes ~3seconds, can be further vectorized but gets across the idea:
n=800;
m=800;
p=50;
H=sparse(n,m);
time_vec=zeros(n/p,1);
i=[];
j=[];
v=[];
t1=tic;
for mm=1:m/p
for ii=1:n/p
for jj=1:p
i(end+1)=(ii-1)*length(p)+1+(mm-1)*m/p;
j(end+1)=ones(length(p),1)*(jj+p*(ii-1));
v(end+1)=ii*ones(length(p),1);
end
end
end
toc(t1)
H=sparse(i,j,v,n,m);