bilinear interpolation of 2D matrix
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad Usman Saleem
am 8 Mär. 2016
Bearbeitet: Muhammad Usman Saleem
am 15 Feb. 2023
I am trying to apply Bilinear/bicubic interpolation on my data set which is in text files. These text files are in a folder and name output_00.text to output_23.text. Each text file consist on three columns. First is Latitude, second is longitude and third column is temperature value at this latitude and longitude(position over earth).
Temperature column contain -9999.000 as not a number or NaN values. This NaN value appear randomly in each file. Some times it appear over start, some times in middle of data, and some times at the end in the file. It is random in appearance.
I want to interpolate these NaN values with bilinear/ bicubic interpolation technique.
This code will read each text file and interpolate it with bilinear method and save it with method_00.text.
My text files has been attached
On google i found a tool for bilinear interpolation over a image or matrix. For the time shake this code can be modify to my requirement. But How? This code as been attached with this question. Link of this tool is here http://www.mathworks.com/matlabcentral/fileexchange/43533-bilinear-interpolation-of-an-image-or-matrix
Thanks always for this kind assistance
Akzeptierte Antwort
Mike Garrity
am 8 Mär. 2016
Here's one approach.
Create an XY grid, but put nans in some of the Z values.
[x,y] = meshgrid(linspace(-3,3,40));
z = peaks(x,y);
m = unique(randi(numel(z),[1 50]));
z(m) = nan;
surf(x,y,z)

m = isnan(z(:));
F = scatteredInterpolant(x(~m),y(~m),z(~m),'linear');
z2 = z;
z2(m) = F(x(m),y(m));
surf(x,y,z2)

What's going on there is that I created a scatteredInterpolant from the locations where there weren't nans (i.e. x(~m),y(~m),z(~m)), and then I applied it at the locations where there are nans (i.e. x(m),y(m)). Does that make sense?
3 Kommentare
Stephen23
am 9 Mär. 2016
Bearbeitet: Stephen23
am 9 Mär. 2016
@Muhammad Usman Saleem
It does not matter how many times you ask, you cannot get the impossible. Bilinear/ bicubic interpolation requires all data on a grid. You have missing data. Ergo you cannot use these methods. This has been explained to you multiple times.
Weitere Antworten (1)
Image Analyst
am 8 Mär. 2016
If your data are in a rectangular grid (i.e., an image), you can use imresize() (in the Image Processing Toolbox) to do bilinear interpolation, or a variety of other interpolations. If they're not in a grid, use scatteredInterpolant like Mike showed you.
5 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation of 2-D Selections in 3-D Grids finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!