MATLAB: How to create an image in Matlab from .txt file

create imageimageimage processingluminosity;

I have some .txt files containing 3 columns of number (x,y,z). z is the luminosity of each point identified by the x,y coordinates. So i have 3 vectors containing 316920 elements each. I should find a way to produce an image file (the format is not important, it may be a .jpg for example) in which the luminosity (z vector) of each point whose coordinates are identified by the first 2 columns of the .txt file (x and y coordinates) vary depending on the third column (vector z). How can I concert the coordinates and luminosity into an image? Thanks!

Best Answer

data = importdata('your text file') ;
x = data(:,1) ;
y = data(:,2) ;
z = data(:,3) ;
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
N = 1000 ; % can be varied
xi = linspace(x0,x1,N) ;
yi = linspace(y0,y1,N) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
surf(X,Y,Z) ;
view(2)
shading interp
axis tight
saveas(gcf,'myfile.jpg')