problem with scatteredInterpolant: are there any limits?

2 views (last 30 days)
the xyz data file consists out of 3157394 data triples like this:
417826.974 5333045.048 1636.000
417826.974 5333045.128 1682.000
417826.974 5333045.208 1744.000
417826.974 5333045.288 1753.000
417826.974 5333045.368 1674.000
417826.974 5333045.448 1689.000
with the key data:
min(x) = 417740; max(x) = 417870; min(y) = 4177412; max(y)= 5333100; min(z)= 0; max(z) = 11054;
length(x) = length(y) = length(z) = 3157394;
First, everything works fine using:
TT=readtable(FileNameNeu,'PreserveVariableNames',true,'NumHeaderLines',1);
x=table2array(TT(:,1));
y=table2array(TT(:,2));
z=table2array(TT(:,3));
scatter3(x,y,z,4,z,'.'); view(2); grid on; daspect([1 1 1]);
But when I try this:
F = scatteredInterpolant(x,y,z,'natural','none'); :
[X,Y] = meshgrid(min(x):0.5:max(x),min(y):0.5:max(y));
Z = F(X,Y);
then I receive the error:
Error using scatteredInterpolant
The coordinates of the input points must be finite values; Inf and NaN are not
permitted.
Error in FillGaps (line 44)
F = scatteredInterpolant(x,y,z,'natural','none'); % create the interpolant
But...there are no Inf's and NaN's in the data file.
The same occurs if I reduce the values of x and z using:
x=x-min(x); y=y-min(y);
What I am doing wrong? Thanks a lot,
Harry
  5 Comments
Harald von der Osten
Harald von der Osten on 14 Nov 2022
417768.334 5333147.288 0.000
417768.334 5333147.368 0.000
417768.334 5333147.448 0.000
line 4177684
417768.414 5332990.328 0.000
417768.414 5332990.408 0.000
417768.414 5332990.488 0.000
417768.414 5332990.568 0.000

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 13 Nov 2022
Edited: Star Strider on 13 Nov 2022
It would help to have the file.
It appears to me that the data might be gridded. To determine that, the easiest way would be:
TT=readtable(FileNameNeu, 'VariableNamingRule','preserve')
x = TT{:,1};
y = TT{:,2};
z = TT{:,3};
[Ux,ixx] = unique(x)
RowSize = unique(ixx)
X = reshape(x,RowSize,[]);
Y = reshape(y,RowSize,[]);
Z = reshape(z,RowSize,[]);
figure
surf(X, Y, Z)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
If that fails (the data not being gridded appropriately), try this —
L = size(TT,1);
xv = linspace(min(x), max(x), L);
yv = linspace(min(y), max(y), L);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
figure
surf(X, Y, Z)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
One of those should work.
EDIT — (13 Nov 2022 at 23:52)
Corrected typographical errors.
.
  2 Comments

Sign in to comment.

More Answers (1)

Bruno Luong
Bruno Luong on 13 Nov 2022
You'll have problem anyway since your data is not centered and especially not normalize.
x range is 130 and y range is 1155688, almost 10000 larger than xrange. Scattered interpolation is based on Delauray triangulation, and that alone will give garbage out.
I believe it written somewhere (tip) this warning in the doc page.
So please do CENTERING and NORMALIZATION data as preproceesing step before interpoltion.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!