Interpolation for x,y,z values
5 views (last 30 days)
Show older comments
Prasad Joshi
on 29 Jul 2022
Commented: Star Strider
on 29 Jul 2022
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')
0 Comments
Accepted Answer
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(:,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
More Answers (1)
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.
See Also
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!