You need to shift at the edge of each tile (ie when tile width -/+ position=matrix tile size, in this case 10 due to size/divisions in matrix)
Posted your code modified below
sync on:sync rate 40
rem ##matrix is 200x150 with 20x20 divs, so tiles are 10x7.5##
make matrix 1,200,150,20,20
randomize matrix 1, 5
do
if leftkey()=1 then sx#=sx#+.2
if rightkey()=1 then sx#=sx#-.2
rem if at edge of matrix tile shift matrix
if sx#<-10.0
shift matrix left 1
sx#=sx#+10.0
endif
if sx#>10.0
shift matrix right 1
sx#=sx#-10.0
endif
rem set height of ground
position matrix 1,sx#,-5,sz#
sync
loop
Think it should be ok
Twynklet