How can I find nearest value in large grid data?

I have a grid having cells 100x60, containing contours data. Some of the cells have filled with whole number from 1 to 15 showing the elevation of contours, now how can I interpolate points between the contours line to fill all empty cells?
Note: Points are not in regular way, these scattered points

Réponses (2)

Walter Roberson
Walter Roberson le 13 Juil 2016

0 votes

See John D'Errico's File Exchange contribution "inpaint_nan"

2 commentaires

Dear Roberson thank you for your response and guideline. The function you have mentioned above is right now harder for me to understand because I am getting started with MATlab, So can you direct me any simplest way possible?
If you download inpaint_nans, it makes the problem pretty easy. For example, say you have some gridded dataset like this:
Z = peaks(100);
but a few points are NaNs:
Z([423 898 1234] = NaN;
You can fill in the missing values like this:
Z_filled = inpaint_nans(Z);

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 13 Juil 2016

0 votes

How about scatteredInterpolant()?

5 commentaires

Zubair Nizamani
Zubair Nizamani le 13 Juil 2016
Modifié(e) : Walter Roberson le 13 Juil 2016
@Image Analyst, I have used the code mentioned below for interpolation, but I made an excel sheet in a way that, divided all the grid in 5x5 square boxes and then I assigned values on every corner of that boxes according to my best assumption, but when I plotted the contours, my contours lines were not smoothed and kinda uneven. So for now I want to make code that reads the excel as it and then interpolate.
If it is possible please do me favor here via helping me out.
[In excel sheet, only contour digitized values are present]
[Code]
clear all;
clc;
data = xlsread('Trial1.xlsx');
rlt = data ;
[height, width] = size(data);
[x,y] = meshgrid(0:5:width,0:5:height);
x(:,1) = 1; y(1,:) = 1;
z(1,1) = data(1,1);
for i = 1:height/5
z(i+1, 1) = data(5*i, 1);
end
for j = 1:width/5
z(1, j+1) = data(1, 5*j);
end
for i = 1:height/5
for j = 1:width/5
z(i+1,j+1) = data(5*i,5*j);
end
end
[x1,y1] = meshgrid(1:width, 1:height);
z1 = interp2(x, y, z, x1, y1, 'spline');
for i = 1:height
for j = 1:width
if ~(data(height-i+1,j) > 0 )
rlt(i,j) = z1(height-i+1,j);
else
rlt(i,j) = data(height-i+1,j);
end
end
end
% figure; mesh(x1,y1,z1); xlabel('longitude'); ylabel('latitude');
% F = [.05 .1 .05; .1 .4 .1; .05 .1 .05];
% ZC = conv2(rlt,F,'same');
xlswrite('digital_value.xlsx', rlt);
figure;
%contour(rlt,20);
[C,h] = contour(rlt);
clabel(C,h);
set(h, 'LevelList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], ...
'TextList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
You forgot to attach the workbook. For the benefit of everyone, attach the workbook AND a screenshot of your plot or image.
What kind of help do you need reading Excel? You obviously know about xlsread(). Do you want to know about ActiveX also?
For instance, If this is my excel sheet or grid data,
0 0 0 1 0 0 2
0 0 1 0 0 2 0
0 1 0 0 2 0 0
1 0 0 2 0 0 0
0 0 2 0 0 0 0
Now can you tell me what is the best way to interpolate the point where zeroes are? and replace all the zeroes with interpolated data.
I need to leave now, but my first attempt would be to use scatteredInterpolant, like I already suggested. But I'm sure you've tried that by now, so let's see your code - it may speed me up when I return later today. If you didn't try my suggestion, then why not?
YourData(YourData == 0) = nan;
Now call the File Exchange contribution inpaint_nan on YourData.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by