# How to fill/interpolate missing data to nearest geospatial coordinate?

8 visualizzazioni (ultimi 30 giorni)
Michelle Pruss il 8 Feb 2024
Commentato: Michelle Pruss il 8 Feb 2024
Hello,
I am trying to interpolate some missing values (NAN) in a dataset that contains Irrigation Well Data with the following columns: Longitude, Latitude, and Pump Rate for each irrigation well. There are no missing Longitude or Latitude values but there are some missing Pump Rate Values. What I would like to do is to fill the missing pump rate values to be interpolated to the nearest Irrigation Well spatially.
I am unsure what function to use and how to do this. I have tried looking at the fillmissing, interp3, and scatterinterpolant but I am not sure what to use or how to use it (i have read through the pages for each and watched videos but am still confused).
Can someone please let me know what function to use and how to use it?
Thank you!!!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Vaibhav il 8 Feb 2024
Hi Michelle
You can use "scatteredInterpolant" function for interpolate missing pump rate values.
The "scatteredInterpolant" function works with unstructured data in N dimensions (in your case, 2 dimensions for the spatial coordinates) and can interpolate values at query points based on the values at the known points.
You can refer to the below steps:
• Separate your known and unknown pump rate data. Let's say you have a matrix wellData with columns for Longitude, Latitude, and Pump Rate.
knownData = wellData(~isnan(wellData(:,3)), :); % Rows without NaN in Pump Rate
unknownData = wellData(isnan(wellData(:,3)), :); % Rows with NaN in Pump Rate
• Use the known data to create the interpolant function.
F = scatteredInterpolant(knownData(:,1), knownData(:,2), knownData(:,3), 'nearest'); % 'nearest' for nearest neighbor interpolation
• Use the interpolant to estimate the missing pump rate values.
interpolatedPumpRates = F(unknownData(:,1), unknownData(:,2));
• Replace the NaN values in the original data with the interpolated values.
wellData(isnan(wellData(:,3)), 3) = interpolatedPumpRates;
When opting for the "nearest" method, you assign the unknown pump rate the value of the closest known pump rate geographically. If you desire a different interpolation approach, such as considering a weighted average of nearby points, you can choose "linear" or "natural" instead of 'nearest' when generating the scatteredInterpolant.
Hope this helps!
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Michelle Pruss il 8 Feb 2024
This worked!! Thank you so much for showing and explaining each step I really appreciate it!!!

Accedi per commentare.

### Più risposte (1)

KSSV il 8 Feb 2024
% Prepare dummy data
[X,Y] = meshgrid(1:10,1:10) ;
Z = rand(size(X)) ;
% Make random nan's
idx = sort(randsample(numel(X),20)) ;
Z(idx) = NaN ;
% Fill the nans
% interpolation
F = scatteredInterpolant(X(~isnan(Z)),Y(~isnan(Z)),Z(~isnan(Z))) ;
Z(idx) = F(X(idx),Y(idx)) ;
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su 3-D Visualization in Help Center e File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by