scatteredInterpolant gives out NaN in some query points

I have 3D-scattered testbench-data with x, y und z as setpoints and I want to make contourf-plots over x and y with z as adjustible parameter.
First i filtered and deleted doubled samples to make sure the datapoints are unique:
% Load Data
load('data.mat');
% Keep unique Data
setpoints = [data.x data.y data.z];
[setpointsu,idx] = unique(setpoints,'rows');
datau = data(idx,:);
Next I defined query-points which grid the room of the scattered data and interpolated:
xq = -50:5:0;
yq = 0:5:30;
zq = 25:5:75;
% Interpolieren
[Xq,Yq,Zq] = meshgrid(xq,yq,zq);
F.Value = scatteredInterpolant(x,y,z,datau.Value,'linear');
P.Value = F.Value(Xq,Yq,Zq);
But unfourtunately P.Value has some NaNs in the middle of the 'query room':
At these Points enough scattered input data should be availabe for interpolation.
What else could be causes for these red circled NaNs?
Thanks for your help.

 Risposta accettata

Bruno Luong
Bruno Luong il 9 Ago 2023
Modificato: Bruno Luong il 9 Ago 2023
Probably your data contains NaN at one or several points.
I don't quite understand your code
datau.Value
seems not valid since datau = data(idx,:); looks like an array.
Please share your data.

6 Commenti

I double checked it and there is no NaN in the considered data channels.
Bruno Luong
Bruno Luong il 9 Ago 2023
Modificato: Bruno Luong il 9 Ago 2023
"Please share your data."
scattered interpolation requires xyz have more or less the same unit, if you have large discrepency might be there is some numerical issue with triangulation (tetrahedrisation in 3D).
Here is the raw data. Its an Import from csv-File.
A = load('data.mat')
A = struct with fields:
data: [230×4 table]
A = table2array(A.data);
any(isnan(A(:)))
ans = logical
1
Your matrix has NaN values in it (see above).
Clearly you have point outside the convexhull AND you have NaN in your data (double check is not enough, quadriple check may be)
load('data.mat')
% Keep unique Data
x=data.x;
y=data.y;
z=data.z;
setpoints = [data.x data.y data.z];
[setpointsu,idx] = unique(setpoints,'rows');
datau = data(idx,:);
xq = -50:5:0;
yq = 0:5:30;
zq = 25:5:75;
% Interpolieren
[Xq,Yq,Zq] = meshgrid(xq,yq,zq);
find(isnan(datau.Value))
ans = 12×1
111 112 113 114 115 116 117 118 119 120
F.Value = scatteredInterpolant(x,y,z,datau.Value,'linear');
P.Value = F.Value(Xq,Yq,Zq);
xq = -50:5:0;
yq = 0:5:30;
zq = 25:5:75;
% Interpolieren
[Xq,Yq,Zq] = meshgrid(xq,yq,zq);
F.Value = scatteredInterpolant(x,y,z,datau.Value,'linear','nearest');
P.Value = F.Value(Xq,Yq,Zq);
P.Value(:,:,4)
ans = 7×11
0.4071 NaN NaN NaN 0.3632 0.4854 0.5979 0.5267 0.4373 0.3391 0.2409 NaN NaN NaN NaN 0.3955 0.4464 0.5515 0.5318 0.5121 0.4251 0.3269 NaN NaN NaN NaN 0.4262 0.4805 0.5317 0.4999 0.4682 0.4420 0.4172 NaN NaN NaN NaN 0.4182 0.3835 0.3556 0.4224 0.4003 0.3738 0.4393 0.5506 0.5072 0.4636 0.4433 0.4093 0.3093 0.1971 0.2639 0.3299 0.3920 0.4541 0.5508 0.5441 0.5064 0.4423 0.3797 0.3150 0.3080 0.2979 0.3229 0.3496 0.4106 0.5508 0.5463 0.5372 0.4609 0.3854 0.3785 0.4076 0.3975 0.3875 0.3774 0.3677
T=delaunayTriangulation(x,y,z);
F = convexHull(T);
close all
trisurf(F,x,y,z)
axis equal
hold on
plot3(Xq(:),Yq(:),Zq(:),'.')
Your are right. Apologies. I checked the wrong column in my raw file.

Accedi per commentare.

Più risposte (1)

By default, scatteredInterpolant with 'linear' method does not do extrapolation. If you attempt to query at a location that is outside the outside boundary of the triangulation of the reference points, then it would need extrapolation but that is not enabled by default for 'linear'

1 Commento

Thank you for your answer.
If I define ExtrapolationMethod as 'linear' there is no change in the outcome.
F.Value = scatteredInterpolant(x,y,z,datau.Value,'linear','linear');
The black x markers are showing the scattered input data points.

Accedi per commentare.

Categorie

Scopri di più su Descriptive Statistics and Insights in Centro assistenza e File Exchange

Prodotti

Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by