How to create a tiff file from a nx3 matrix
3 views (last 30 days)
Show older comments
I have data from an nx3 matrix where column 1 is the x value, column 2 is the y value, and column 3 is an attribute value. Is it possible to create a tiff file using this information? I've been trying to use the Tiff command but I don't think I am setting up tagstruct correctly, because I continue to get errors when I try to write. Thanks.
0 Comments
Accepted Answer
KSSV
on 17 Jul 2020
Let data be your n*3 matrix.
x = data(:,1) ;
y = data(:,2) ;
z = data(:,3) ;
% convert the data to grid
nx = 500 ; ny = 500 ;
xi = linspace(min(x),max(x),nx) ;
yi = linspace(min(y),max(y),ny) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
% write to tiff file
lonmin = min(x); lonmax = max(x);
latmin = min(y); latmax = max(y);
% Write to geotiff
R = georasterref('RasterSize',size(Z),'LatitudeLimits',[latmin,latmax],'LongitudeLimits',[lonmin,lonmax]);
tiffile = strcat('myFile','.tif') ;
geotiffwrite(tiffile,Z,R)
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!