If you want to stitch together 100 images to make a 3-D matrix, which is what it looks like you're trying to do with "X=[X temp];" and want "a N1*N2xM matrix" then do this
if i == 1
X = img;
X = cat(3, X, X);
and of course, don't use eval().