You can use "save array" and "load array" to do it quickly and painlessly on one line.
` Create the matrix
global tilex=50
global tilez=50
make matrix 1,1000,1000,tilex,tilez
` Make random heights
randomize matrix 1,20
update matrix 1
File$="test1.txt"
SaveMatrix(File$)
wait key
` Reset matrix to zero (to show this works)
for tx = 0 to tilex
for tz = 0 to tilez
set matrix height 1,tx,tz,0
next tz
next tx
update matrix 1
wait key
LoadMatrix(File$)
wait key
` Save Matrix(Filename$)
function SaveMatrix(t$)
local dim matheight#(tilex,tilez)
for tx = 0 to tilex
for tz = 0 to tilez
matheight#(tx,tz) = get matrix height(1,tx,tz)
next tz
next tx
save array t$,matheight#(0)
endfunction
` Load Matrix(Filename$)
function LoadMatrix(t$)
local dim matheight#(tilex,tilez)
load array t$,matheight#(0)
for tx = 0 to tilex
for tz = 0 to tilez
set matrix height 1,tx,tz,matheight#(tx,tz)
next tz
next tx
update matrix 1
endfunction