x=-2:.1:2;
y=x;
[X,Y]=meshgrid(x,y);
Z=exp(-X.^2-Y.^2);
n=length(x);

fileID = fopen('testmy.obj','w');
format1= 'v %4.2f %4.2f %4.2f \n'; 
format2= 'f %5d %5d %5d %5d \n';

for i=1:n;
    for j=1:n;
        c1=Z(i,j);c2=i/n;c3=j/n;
fprintf(fileID,format1,X(i,j),Y(i,j),Z(i,j));
    end
end
for i=1:n;
    for j=1:n;
        v1=i+(j-1)*n; v2=i+1+(j-1)*n; 
        v3=i+j*n;   v4=i+1+j*n;
fprintf(fileID,format2,v1,v2,v3,v4);
    end
end



fclose(fileID);
