Interpolation for x,y,z values

4 views (last 30 days)
I am doing interpolation of z using x & y values ..But I am getting NAN values using interpolation how can I removed this NAN and interpolate it to gives actual Value.. I am herewith attaching my Excel file, code and error
clear all
close all
clc
a=xlsread('Book2.xlsx')
x = a(:,1);
y =a(:,2);
z = a(:,3);
xq=[800 1000 1250 1500 1750 2100 2500 3000 3500 4000 4500 5000 5500 6000 6500];
yq=(100:100:2700)'
vq = griddata(x,y,z,xq,yq)
mesh(xq,yq,vq)
hold on
plot3(x,y,z,'o')

Accepted Answer

Star Strider
Star Strider on 29 Jul 2022
The data in the file do not appear to resemble the data in the image.
For those, the fillmissing function (R2016b and later releases) is likely the best option, however it will be necessary for you to experiment to get the desired result—
a = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1081705/Book2.xlsx', 'VariableNamingRule','preserve')
a = 37×3 table
N PCOL TAPE (iso) ______ ______ __________ 799.94 660 30.28 800.01 359.9 37.21 800.08 1011.3 28.63 1250 660 48.64 1250 1552.3 28.76 1250 360 52.57 1250.2 1020 28.19 1749.9 359.9 47.8 1750 1020.3 26.61 1750 2234 30.51 1750.1 660 48.77 2499 839.9 28.27 2499.7 2317.7 31.83 2500.7 360 35.03 2500.9 2312.7 31.92 2501.1 1020.2 26.76
a(:,1:3) = fillmissing(a(:,1:3), 'makima', 'EndValues','extrap') % Experiment With The 'method' (Here: 'makima'), The 'EndValues' extrapolation use the same 'method'
x = a{:,1};
y = a{:,2};
z = a{:,3};
L = size(a,1);
xq = linspace(min(x), max(x), L);
yq = linspace(min(y), max(y), L);
[X,Y] = ndgrid(xq, yq);
Z = griddata(x, y, z, X, Y);
figure
surfc(X, Y, Z)
grid on
.
  6 Comments
Star Strider
Star Strider on 29 Jul 2022
As always, my pleasure!

Sign in to comment.

More Answers (1)

Mathias Smeets
Mathias Smeets on 29 Jul 2022
You are getting NaN points because some query points (for example your lowest y-values) are outside your actual data. It is not possible to extrapolate with the griddata function. Look this link for more information.

Categories

Find more on Interpolation 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!