You have a couple of typing errors.
1. Your second For Loop
For( k = 2, k <= N Items( cols ), i++,
you are incrementing "i", not "k". It should be
For( k = 2, k <= N Items( cols ), k++,
Secondly, you need to subtract 1 from k when referencing your MainData matrix, otherwise you will go beyond the range, since it is 1 less than the number of columns.
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
The whole section should be:
For( i = 1, i <= N Rows( rowlist ), i++,
For( k = 2, k <= N Items( cols ), k++,
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
)
);
Jim