MATLAB: Can anyone show me how I can avoid following for loops

thanks

*Hello everyone,
Can anyone show me how I can avoid following for loops.
Thanks!*
mth=0;
nth=0;
for i=1:1000
ML = [1,2;3,4];
for ix=1:size(ML,1)
for iy=1:size(ML,2)
M(mth+ix,nth+iy)=ML(ix,iy);
end
end
mth = mth+size(ML,1);
nth = nth+size(ML,2);
end

Best Answer

Here is a one approach:
M = diag(repmat([1 4],1,1000)) +...
diag([repmat([2 0],1,999) 2],1) +...
diag([repmat([3 0],1,999) 3],-1);
And another:
M = diag(repmat([1 4],1,1000));
M(2001:2001:end) = [repmat([2 0],1,999) 2];
M(2:2001:end) = [repmat([3 0],1,999) 3];