// save img as PGM(P2,ascii) image format function imshow(img) w=size(img,2); h=size(img,1); fd=mopen('save.pgm', 'w'); mfprintf(fd, 'P2\n%d %d\n255\n', w, h); for i=1:h for j=1:w mfprintf(fd,'%d ', img(i,j)*255); end end mclose(fd); endfunction