Interpolation for x,y,z values
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-7-29
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 个评论
更多回答(1 个)
Mathias Smeets
2022-7-29
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!