Receiving "Error using griddedInterpolant. Grid arrays must have NDGRID structure." error when interpolating 3D data.
Mostrar comentarios más antiguos
Dear community
I am using the griddedInterpolant() function to fit N-D data. In my particular case, the input has dimension 19x4x4.
The special thing is that one of the axes, the x-axis, is not constructed using incresing numbers (like from linspace or logspace). Instead, it comes from a separate .csv file because its values are also dependent on Y and Z.
Here is a code example:
clc; clear; close all; format shorteng;
X_range = zeros(1,19); % Placeholder for external data
Y_range = logspace(log10(210e-9),log10(100e-6),4);
Z_range = logspace(log10(180e-9),log10(100e-6),4);
[X,Y,Z] = ndgrid(X_range, Y_range,Z_range);
for k=1:19
% In reality, this data is read from a .csv file.
% For this example, let's use some random numbers
X(k,:,:) = randn(4,4);
end
% Generate a random result matrix
res = randn(19,4,4);
% Compute spline interpolation
F = griddedInterpolant(X,Y,Z,res,'spline');
This results in a "Grid array must have NDGRID structure" error. What is the problem here?
Edit 28.12.2021
I want to update my question according to the suggestion in the comments.
Namely, "scatteredInterpolant(P,v) specifies the coordinates of the sample points as an array. The rows of P contain the (x, y) or (x, y, z) coordinates for the values in v."
Below is an example that converts my case to this encoding (this time with real data).
clc; clear; close all; format shorteng;
X_matrix = [2.11300000000000e-12 1.76200000000000e-12 1.02000000000000e-11 7.76800000000000e-11 1.49400000000000e-13 1.28200000000000e-13 6.73000000000000e-13 4.99800000000000e-12 2.99000000000000e-14 2.63200000000000e-14 1.50400000000000e-13 1.12900000000000e-12 3.85900000000000e-15 3.36900000000000e-15 1.94600000000000e-14 1.46200000000000e-13
3.16900000000000e-11 2.65800000000000e-11 1.54000000000000e-10 1.17300000000000e-09 2.23800000000000e-12 1.93600000000000e-12 1.01700000000000e-11 7.55300000000000e-11 4.45700000000000e-13 3.96800000000000e-13 2.27000000000000e-12 1.70400000000000e-11 5.75000000000000e-14 5.07800000000000e-14 2.93600000000000e-13 2.20700000000000e-12
4.61500000000000e-10 3.95600000000000e-10 2.29800000000000e-09 1.75000000000000e-08 3.24500000000000e-11 2.89000000000000e-11 1.52400000000000e-10 1.13200000000000e-09 6.35900000000000e-12 5.89600000000000e-12 3.38600000000000e-11 2.54300000000000e-10 8.18200000000000e-13 7.54100000000000e-13 4.37800000000000e-12 3.29200000000000e-11
6.10000000000000e-09 5.60600000000000e-09 3.28600000000000e-08 2.50400000000000e-07 4.23400000000000e-10 4.14100000000000e-10 2.21100000000000e-09 1.64500000000000e-08 7.93500000000000e-11 8.31300000000000e-11 4.84100000000000e-10 3.64100000000000e-09 1.01400000000000e-11 1.06100000000000e-11 6.24500000000000e-11 4.70400000000000e-10
6.43600000000000e-08 6.82100000000000e-08 4.10000000000000e-07 3.13200000000000e-06 4.39800000000000e-09 5.21900000000000e-09 2.89300000000000e-08 2.16100000000000e-07 7.69000000000000e-10 1.00400000000000e-09 6.07200000000000e-09 4.58700000000000e-08 9.74000000000000e-11 1.27500000000000e-10 7.79000000000000e-10 5.89300000000000e-09
4.95500000000000e-07 6.09800000000000e-07 3.81500000000000e-06 2.92400000000000e-05 3.41900000000000e-08 5.07500000000000e-08 2.99900000000000e-07 2.25800000000000e-06 5.51200000000000e-09 9.24900000000000e-09 5.91200000000000e-08 4.49700000000000e-07 6.91400000000000e-10 1.16700000000000e-09 7.53300000000000e-09 5.73700000000000e-08
2.38000000000000e-06 3.90700000000000e-06 2.53600000000000e-05 0.000195000000000000 1.71000000000000e-07 3.63800000000000e-07 2.31200000000000e-06 1.75700000000000e-05 2.48500000000000e-08 6.23000000000000e-08 4.24700000000000e-07 3.25700000000000e-06 3.08100000000000e-09 7.82000000000000e-09 5.37500000000000e-08 4.12600000000000e-07
6.70400000000000e-06 1.72100000000000e-05 0.000117600000000000 0.000908300000000000 5.16300000000000e-07 1.69800000000000e-06 1.17100000000000e-05 8.99400000000000e-05 6.96700000000000e-08 2.64200000000000e-07 1.92400000000000e-06 1.48800000000000e-05 8.56900000000000e-09 3.28800000000000e-08 2.40900000000000e-07 1.86500000000000e-06
1.32000000000000e-05 4.82600000000000e-05 0.000346900000000000 0.00269000000000000 1.10600000000000e-06 4.91600000000000e-06 3.59100000000000e-05 0.000277900000000000 1.43500000000000e-07 7.09400000000000e-07 5.38300000000000e-06 4.18700000000000e-05 1.75700000000000e-08 8.76900000000000e-08 6.68500000000000e-07 5.20200000000000e-06
2.12200000000000e-05 9.61100000000000e-05 0.000713500000000000 0.00554900000000000 1.94200000000000e-06 1.02400000000000e-05 7.71300000000000e-05 0.000599400000000000 2.46700000000000e-07 1.41600000000000e-06 1.09800000000000e-05 8.56200000000000e-05 3.01400000000000e-08 1.74400000000000e-07 1.35700000000000e-06 1.05900000000000e-05
3.02900000000000e-05 0.000155900000000000 0.00117900000000000 0.00918800000000000 3.02000000000000e-06 1.75700000000000e-05 0.000134400000000000 0.00104700000000000 3.79600000000000e-07 2.37600000000000e-06 1.86200000000000e-05 0.000145400000000000 4.63400000000000e-08 2.92100000000000e-07 2.29600000000000e-06 1.79400000000000e-05
4.01000000000000e-05 0.000223800000000000 0.00171200000000000 0.0133500000000000 4.33800000000000e-06 2.67800000000000e-05 0.000206500000000000 0.00161000000000000 5.42300000000000e-07 3.57700000000000e-06 2.81900000000000e-05 0.000220400000000000 6.61400000000000e-08 4.39400000000000e-07 3.47300000000000e-06 2.71600000000000e-05
5.03800000000000e-05 0.000297200000000000 0.00228900000000000 0.0178600000000000 5.88500000000000e-06 3.77100000000000e-05 0.000292200000000000 0.00228000000000000 7.34000000000000e-07 5.00600000000000e-06 3.95900000000000e-05 0.000309600000000000 8.95000000000000e-08 6.14900000000000e-07 4.87500000000000e-06 3.81300000000000e-05
6.09500000000000e-05 0.000374300000000000 0.00289600000000000 0.0226100000000000 7.64600000000000e-06 5.02100000000000e-05 0.000390100000000000 0.00304400000000000 9.53400000000000e-07 6.64700000000000e-06 5.26500000000000e-05 0.000411800000000000 1.16200000000000e-07 8.16500000000000e-07 6.48400000000000e-06 5.07300000000000e-05
7.16700000000000e-05 0.000453600000000000 0.00352200000000000 0.0275000000000000 9.60200000000000e-06 6.40800000000000e-05 0.000498600000000000 0.00389100000000000 1.19900000000000e-06 8.48000000000000e-06 6.72200000000000e-05 0.000525900000000000 1.46200000000000e-07 1.04200000000000e-06 8.28000000000000e-06 6.47900000000000e-05
8.24400000000000e-05 0.000534400000000000 0.00415800000000000 0.0324800000000000 1.17300000000000e-05 7.91400000000000e-05 0.000616000000000000 0.00480800000000000 1.46700000000000e-06 1.04800000000000e-05 8.31000000000000e-05 0.000650100000000000 1.78900000000000e-07 1.28800000000000e-06 1.02400000000000e-05 8.01200000000000e-05
9.31900000000000e-05 0.000615800000000000 0.00479900000000000 0.0374900000000000 1.40000000000000e-05 9.51600000000000e-05 0.000740700000000000 0.00578200000000000 1.75600000000000e-06 1.26200000000000e-05 0.000100100000000000 0.000783000000000000 2.14200000000000e-07 1.55200000000000e-06 1.23400000000000e-05 9.65400000000000e-05
0.000103900000000000 0.000697300000000000 0.00544100000000000 0.0425100000000000 1.64000000000000e-05 0.000111900000000000 0.000871100000000000 0.00679900000000000 2.06300000000000e-06 1.48800000000000e-05 0.000118000000000000 0.000922900000000000 2.51600000000000e-07 1.83100000000000e-06 1.45500000000000e-05 0.000113800000000000
0.000114400000000000 0.000778600000000000 0.00608100000000000 0.0475100000000000 1.88900000000000e-05 0.000129300000000000 0.00100500000000000 0.00784700000000000 2.38300000000000e-06 1.72400000000000e-05 0.000136600000000000 0.00106800000000000 2.90800000000000e-07 2.12100000000000e-06 1.68500000000000e-05 0.000131900000000000];
V_matrix = [-0.508800000000000 -0.625100000000000 -0.637000000000000 -0.638000000000000 -0.503700000000000 -0.602700000000000 -0.614500000000000 -0.616000000000000 -0.486500000000000 -0.581400000000000 -0.590900000000000 -0.592100000000000 -0.484000000000000 -0.578900000000000 -0.588000000000000 -0.589200000000000
-0.408800000000000 -0.525100000000000 -0.537000000000000 -0.538000000000000 -0.403700000000000 -0.502700000000000 -0.514500000000000 -0.516000000000000 -0.386500000000000 -0.481400000000000 -0.490900000000000 -0.492100000000000 -0.384000000000000 -0.478900000000000 -0.488000000000000 -0.489200000000000
-0.308800000000000 -0.425100000000000 -0.437000000000000 -0.438000000000000 -0.303700000000000 -0.402700000000000 -0.414500000000000 -0.416000000000000 -0.286500000000000 -0.381400000000000 -0.390900000000000 -0.392100000000000 -0.284000000000000 -0.378900000000000 -0.388000000000000 -0.389200000000000
-0.208800000000000 -0.325100000000000 -0.337000000000000 -0.338000000000000 -0.203700000000000 -0.302700000000000 -0.314500000000000 -0.316000000000000 -0.186500000000000 -0.281400000000000 -0.290900000000000 -0.292100000000000 -0.184000000000000 -0.278900000000000 -0.288000000000000 -0.289200000000000
-0.108800000000000 -0.225100000000000 -0.237000000000000 -0.238000000000000 -0.103700000000000 -0.202700000000000 -0.214500000000000 -0.216000000000000 -0.0864800000000000 -0.181400000000000 -0.190900000000000 -0.192100000000000 -0.0840200000000000 -0.178900000000000 -0.188000000000000 -0.189200000000000
-0.00884400000000000 -0.125100000000000 -0.137000000000000 -0.138000000000000 -0.00365500000000000 -0.102700000000000 -0.114500000000000 -0.116000000000000 0.0135200000000000 -0.0814400000000000 -0.0909100000000000 -0.0921100000000000 0.0159800000000000 -0.0788800000000000 -0.0880300000000000 -0.0891900000000000
0.0911600000000000 -0.0250600000000000 -0.0370000000000000 -0.0380300000000000 0.0963400000000000 -0.00272500000000000 -0.0144900000000000 -0.0159800000000000 0.113500000000000 0.0185600000000000 0.00908500000000000 0.00788900000000000 0.116000000000000 0.0211200000000000 0.0119700000000000 0.0108100000000000
0.191200000000000 0.0749400000000000 0.0630000000000000 0.0619700000000000 0.196300000000000 0.0972800000000000 0.0855100000000000 0.0840200000000000 0.213500000000000 0.118600000000000 0.109100000000000 0.107900000000000 0.216000000000000 0.121100000000000 0.112000000000000 0.110800000000000
0.291200000000000 0.174900000000000 0.163000000000000 0.162000000000000 0.296300000000000 0.197300000000000 0.185500000000000 0.184000000000000 0.313500000000000 0.218600000000000 0.209100000000000 0.207900000000000 0.316000000000000 0.221100000000000 0.212000000000000 0.210800000000000
0.391200000000000 0.274900000000000 0.263000000000000 0.262000000000000 0.396300000000000 0.297300000000000 0.285500000000000 0.284000000000000 0.413500000000000 0.318600000000000 0.309100000000000 0.307900000000000 0.416000000000000 0.321100000000000 0.312000000000000 0.310800000000000
0.491200000000000 0.374900000000000 0.363000000000000 0.362000000000000 0.496300000000000 0.397300000000000 0.385500000000000 0.384000000000000 0.513500000000000 0.418600000000000 0.409100000000000 0.407900000000000 0.516000000000000 0.421100000000000 0.412000000000000 0.410800000000000
0.591200000000000 0.474900000000000 0.463000000000000 0.462000000000000 0.596300000000000 0.497300000000000 0.485500000000000 0.484000000000000 0.613500000000000 0.518600000000000 0.509100000000000 0.507900000000000 0.616000000000000 0.521100000000000 0.512000000000000 0.510800000000000
0.691200000000000 0.574900000000000 0.563000000000000 0.562000000000000 0.696300000000000 0.597300000000000 0.585500000000000 0.584000000000000 0.713500000000000 0.618600000000000 0.609100000000000 0.607900000000000 0.716000000000000 0.621100000000000 0.612000000000000 0.610800000000000
0.791200000000000 0.674900000000000 0.663000000000000 0.662000000000000 0.796300000000000 0.697300000000000 0.685500000000000 0.684000000000000 0.813500000000000 0.718600000000000 0.709100000000000 0.707900000000000 0.816000000000000 0.721100000000000 0.712000000000000 0.710800000000000
0.891200000000000 0.774900000000000 0.763000000000000 0.762000000000000 0.896300000000000 0.797300000000000 0.785500000000000 0.784000000000000 0.913500000000000 0.818600000000000 0.809100000000000 0.807900000000000 0.916000000000000 0.821100000000000 0.812000000000000 0.810800000000000
0.991200000000000 0.874900000000000 0.863000000000000 0.862000000000000 0.996300000000000 0.897300000000000 0.885500000000000 0.884000000000000 1.01400000000000 0.918600000000000 0.909100000000000 0.907900000000000 1.01600000000000 0.921100000000000 0.912000000000000 0.910800000000000
1.09100000000000 0.974900000000000 0.963000000000000 0.962000000000000 1.09600000000000 0.997300000000000 0.985500000000000 0.984000000000000 1.11400000000000 1.01900000000000 1.00900000000000 1.00800000000000 1.11600000000000 1.02100000000000 1.01200000000000 1.01100000000000
1.19100000000000 1.07500000000000 1.06300000000000 1.06200000000000 1.19600000000000 1.09700000000000 1.08600000000000 1.08400000000000 1.21400000000000 1.11900000000000 1.10900000000000 1.10800000000000 1.21600000000000 1.12100000000000 1.11200000000000 1.11100000000000
1.29100000000000 1.17500000000000 1.16300000000000 1.16200000000000 1.29600000000000 1.19700000000000 1.18600000000000 1.18400000000000 1.31400000000000 1.21900000000000 1.20900000000000 1.20800000000000 1.31600000000000 1.22100000000000 1.21200000000000 1.21100000000000];
y_range = logspace(log10(210e-9),log10(100e-6),4);
z_range = logspace(log10(180e-9),log10(100e-6),4);
% Encode data in P and v
% Note: I am pretty sure there are better ways to do this
P = zeros(19*4*4,3);
v = zeros(19*4*4,1);
x_cnt = 1;
y_cnt = 1;
z_cnt = 1;
for i=1:19
for j=1:(4*4)
v(x_cnt,1) = V_matrix(i,j);
P(x_cnt,1) = X_matrix(i,j);
P(x_cnt,2) = y_range(y_cnt);
P(x_cnt,3) = z_range(z_cnt);
x_cnt = x_cnt + 1;
y_cnt = y_cnt + 1;
if(y_cnt>4)
y_cnt = 1;
z_cnt = z_cnt + 1;
if(z_cnt>4)
z_cnt = 1;
end
end
end
end
% Interpolate
F_Veff_ne = scatteredInterpolant(P,v,'natural');
% Visualization
xx = logspace(log10(5e-15),log10(20e-6),20); % This range is slimmer because values above 20e-6 are not of interest.
yy = logspace(log10(210e-9),log10(100e-6),20);
zz = logspace(log10(180e-9),log10(100e-6),20);
[xq,yq,zq] = meshgrid(xx,yy,zz);
vq = F_Veff_ne(xq,yq,zq);
xslice = [5e-15, 5e-12, 5e-9, 5e-6];
yslice = [0.5e-6, 5e-6, 50e-6];
zslice = [0.5e-6, 5e-6, 50e-6];
slice(xq,yq,zq,vq,xslice,yslice,zslice)
set(gca,'XScale','log')
set(gca,'YScale','log')
set(gca,'ZScale','log')
xlabel('x')
ylabel('y')
zlabel('z')
cb = colorbar;
cb.Label.String = 'v';
Problem:
The scatteredInterpolant method returns many NaN values when I use the "natural" method (to achieve C1 smoothness). Why? How to avoid this?
5 comentarios
A gridded interpolant requires that its input data are on a regular grid:
If the X values are random**, then they are not gridded, they are scattered. So you would need to use a scattered interpolant.
** or in any other way non-sequentially ordered.
Dominik Hiltbrunner
el 28 de Dic. de 2021
Sargondjani
el 28 de Dic. de 2021
Editada: Walter Roberson
el 28 de Dic. de 2021
The problem is you take log10, and then evaluate them, so x, y, and z are of the orders -15 to -6.
xx = logspace(log10(5e-15),log10(20e-6),20); % This range is slimmer because values above 20e-6 are not of interest.
yy = logspace(log10(210e-9),log10(100e-6),20);
zz = logspace(log10(180e-9),log10(100e-6),20);
[xq,yq,zq] = meshgrid(xx,yy,zz);
vq = F_Veff_ne(xq,yq,zq);
Walter Roberson
el 28 de Dic. de 2021
I do not see why that would be a problem? scatteredInterpolant does not require that the mesh be equally dense for the query locations.
Sargondjani
el 28 de Dic. de 2021
Editada: Sargondjani
el 28 de Dic. de 2021
Sorry, I wasn't awake myself :/
Respuestas (1)
Walter Roberson
el 28 de Dic. de 2021
Editada: Walter Roberson
el 28 de Dic. de 2021
clc; clear; close all; format shorteng;
X_matrix = [2.11300000000000e-12 1.76200000000000e-12 1.02000000000000e-11 7.76800000000000e-11 1.49400000000000e-13 1.28200000000000e-13 6.73000000000000e-13 4.99800000000000e-12 2.99000000000000e-14 2.63200000000000e-14 1.50400000000000e-13 1.12900000000000e-12 3.85900000000000e-15 3.36900000000000e-15 1.94600000000000e-14 1.46200000000000e-13
3.16900000000000e-11 2.65800000000000e-11 1.54000000000000e-10 1.17300000000000e-09 2.23800000000000e-12 1.93600000000000e-12 1.01700000000000e-11 7.55300000000000e-11 4.45700000000000e-13 3.96800000000000e-13 2.27000000000000e-12 1.70400000000000e-11 5.75000000000000e-14 5.07800000000000e-14 2.93600000000000e-13 2.20700000000000e-12
4.61500000000000e-10 3.95600000000000e-10 2.29800000000000e-09 1.75000000000000e-08 3.24500000000000e-11 2.89000000000000e-11 1.52400000000000e-10 1.13200000000000e-09 6.35900000000000e-12 5.89600000000000e-12 3.38600000000000e-11 2.54300000000000e-10 8.18200000000000e-13 7.54100000000000e-13 4.37800000000000e-12 3.29200000000000e-11
6.10000000000000e-09 5.60600000000000e-09 3.28600000000000e-08 2.50400000000000e-07 4.23400000000000e-10 4.14100000000000e-10 2.21100000000000e-09 1.64500000000000e-08 7.93500000000000e-11 8.31300000000000e-11 4.84100000000000e-10 3.64100000000000e-09 1.01400000000000e-11 1.06100000000000e-11 6.24500000000000e-11 4.70400000000000e-10
6.43600000000000e-08 6.82100000000000e-08 4.10000000000000e-07 3.13200000000000e-06 4.39800000000000e-09 5.21900000000000e-09 2.89300000000000e-08 2.16100000000000e-07 7.69000000000000e-10 1.00400000000000e-09 6.07200000000000e-09 4.58700000000000e-08 9.74000000000000e-11 1.27500000000000e-10 7.79000000000000e-10 5.89300000000000e-09
4.95500000000000e-07 6.09800000000000e-07 3.81500000000000e-06 2.92400000000000e-05 3.41900000000000e-08 5.07500000000000e-08 2.99900000000000e-07 2.25800000000000e-06 5.51200000000000e-09 9.24900000000000e-09 5.91200000000000e-08 4.49700000000000e-07 6.91400000000000e-10 1.16700000000000e-09 7.53300000000000e-09 5.73700000000000e-08
2.38000000000000e-06 3.90700000000000e-06 2.53600000000000e-05 0.000195000000000000 1.71000000000000e-07 3.63800000000000e-07 2.31200000000000e-06 1.75700000000000e-05 2.48500000000000e-08 6.23000000000000e-08 4.24700000000000e-07 3.25700000000000e-06 3.08100000000000e-09 7.82000000000000e-09 5.37500000000000e-08 4.12600000000000e-07
6.70400000000000e-06 1.72100000000000e-05 0.000117600000000000 0.000908300000000000 5.16300000000000e-07 1.69800000000000e-06 1.17100000000000e-05 8.99400000000000e-05 6.96700000000000e-08 2.64200000000000e-07 1.92400000000000e-06 1.48800000000000e-05 8.56900000000000e-09 3.28800000000000e-08 2.40900000000000e-07 1.86500000000000e-06
1.32000000000000e-05 4.82600000000000e-05 0.000346900000000000 0.00269000000000000 1.10600000000000e-06 4.91600000000000e-06 3.59100000000000e-05 0.000277900000000000 1.43500000000000e-07 7.09400000000000e-07 5.38300000000000e-06 4.18700000000000e-05 1.75700000000000e-08 8.76900000000000e-08 6.68500000000000e-07 5.20200000000000e-06
2.12200000000000e-05 9.61100000000000e-05 0.000713500000000000 0.00554900000000000 1.94200000000000e-06 1.02400000000000e-05 7.71300000000000e-05 0.000599400000000000 2.46700000000000e-07 1.41600000000000e-06 1.09800000000000e-05 8.56200000000000e-05 3.01400000000000e-08 1.74400000000000e-07 1.35700000000000e-06 1.05900000000000e-05
3.02900000000000e-05 0.000155900000000000 0.00117900000000000 0.00918800000000000 3.02000000000000e-06 1.75700000000000e-05 0.000134400000000000 0.00104700000000000 3.79600000000000e-07 2.37600000000000e-06 1.86200000000000e-05 0.000145400000000000 4.63400000000000e-08 2.92100000000000e-07 2.29600000000000e-06 1.79400000000000e-05
4.01000000000000e-05 0.000223800000000000 0.00171200000000000 0.0133500000000000 4.33800000000000e-06 2.67800000000000e-05 0.000206500000000000 0.00161000000000000 5.42300000000000e-07 3.57700000000000e-06 2.81900000000000e-05 0.000220400000000000 6.61400000000000e-08 4.39400000000000e-07 3.47300000000000e-06 2.71600000000000e-05
5.03800000000000e-05 0.000297200000000000 0.00228900000000000 0.0178600000000000 5.88500000000000e-06 3.77100000000000e-05 0.000292200000000000 0.00228000000000000 7.34000000000000e-07 5.00600000000000e-06 3.95900000000000e-05 0.000309600000000000 8.95000000000000e-08 6.14900000000000e-07 4.87500000000000e-06 3.81300000000000e-05
6.09500000000000e-05 0.000374300000000000 0.00289600000000000 0.0226100000000000 7.64600000000000e-06 5.02100000000000e-05 0.000390100000000000 0.00304400000000000 9.53400000000000e-07 6.64700000000000e-06 5.26500000000000e-05 0.000411800000000000 1.16200000000000e-07 8.16500000000000e-07 6.48400000000000e-06 5.07300000000000e-05
7.16700000000000e-05 0.000453600000000000 0.00352200000000000 0.0275000000000000 9.60200000000000e-06 6.40800000000000e-05 0.000498600000000000 0.00389100000000000 1.19900000000000e-06 8.48000000000000e-06 6.72200000000000e-05 0.000525900000000000 1.46200000000000e-07 1.04200000000000e-06 8.28000000000000e-06 6.47900000000000e-05
8.24400000000000e-05 0.000534400000000000 0.00415800000000000 0.0324800000000000 1.17300000000000e-05 7.91400000000000e-05 0.000616000000000000 0.00480800000000000 1.46700000000000e-06 1.04800000000000e-05 8.31000000000000e-05 0.000650100000000000 1.78900000000000e-07 1.28800000000000e-06 1.02400000000000e-05 8.01200000000000e-05
9.31900000000000e-05 0.000615800000000000 0.00479900000000000 0.0374900000000000 1.40000000000000e-05 9.51600000000000e-05 0.000740700000000000 0.00578200000000000 1.75600000000000e-06 1.26200000000000e-05 0.000100100000000000 0.000783000000000000 2.14200000000000e-07 1.55200000000000e-06 1.23400000000000e-05 9.65400000000000e-05
0.000103900000000000 0.000697300000000000 0.00544100000000000 0.0425100000000000 1.64000000000000e-05 0.000111900000000000 0.000871100000000000 0.00679900000000000 2.06300000000000e-06 1.48800000000000e-05 0.000118000000000000 0.000922900000000000 2.51600000000000e-07 1.83100000000000e-06 1.45500000000000e-05 0.000113800000000000
0.000114400000000000 0.000778600000000000 0.00608100000000000 0.0475100000000000 1.88900000000000e-05 0.000129300000000000 0.00100500000000000 0.00784700000000000 2.38300000000000e-06 1.72400000000000e-05 0.000136600000000000 0.00106800000000000 2.90800000000000e-07 2.12100000000000e-06 1.68500000000000e-05 0.000131900000000000];
V_matrix = [-0.508800000000000 -0.625100000000000 -0.637000000000000 -0.638000000000000 -0.503700000000000 -0.602700000000000 -0.614500000000000 -0.616000000000000 -0.486500000000000 -0.581400000000000 -0.590900000000000 -0.592100000000000 -0.484000000000000 -0.578900000000000 -0.588000000000000 -0.589200000000000
-0.408800000000000 -0.525100000000000 -0.537000000000000 -0.538000000000000 -0.403700000000000 -0.502700000000000 -0.514500000000000 -0.516000000000000 -0.386500000000000 -0.481400000000000 -0.490900000000000 -0.492100000000000 -0.384000000000000 -0.478900000000000 -0.488000000000000 -0.489200000000000
-0.308800000000000 -0.425100000000000 -0.437000000000000 -0.438000000000000 -0.303700000000000 -0.402700000000000 -0.414500000000000 -0.416000000000000 -0.286500000000000 -0.381400000000000 -0.390900000000000 -0.392100000000000 -0.284000000000000 -0.378900000000000 -0.388000000000000 -0.389200000000000
-0.208800000000000 -0.325100000000000 -0.337000000000000 -0.338000000000000 -0.203700000000000 -0.302700000000000 -0.314500000000000 -0.316000000000000 -0.186500000000000 -0.281400000000000 -0.290900000000000 -0.292100000000000 -0.184000000000000 -0.278900000000000 -0.288000000000000 -0.289200000000000
-0.108800000000000 -0.225100000000000 -0.237000000000000 -0.238000000000000 -0.103700000000000 -0.202700000000000 -0.214500000000000 -0.216000000000000 -0.0864800000000000 -0.181400000000000 -0.190900000000000 -0.192100000000000 -0.0840200000000000 -0.178900000000000 -0.188000000000000 -0.189200000000000
-0.00884400000000000 -0.125100000000000 -0.137000000000000 -0.138000000000000 -0.00365500000000000 -0.102700000000000 -0.114500000000000 -0.116000000000000 0.0135200000000000 -0.0814400000000000 -0.0909100000000000 -0.0921100000000000 0.0159800000000000 -0.0788800000000000 -0.0880300000000000 -0.0891900000000000
0.0911600000000000 -0.0250600000000000 -0.0370000000000000 -0.0380300000000000 0.0963400000000000 -0.00272500000000000 -0.0144900000000000 -0.0159800000000000 0.113500000000000 0.0185600000000000 0.00908500000000000 0.00788900000000000 0.116000000000000 0.0211200000000000 0.0119700000000000 0.0108100000000000
0.191200000000000 0.0749400000000000 0.0630000000000000 0.0619700000000000 0.196300000000000 0.0972800000000000 0.0855100000000000 0.0840200000000000 0.213500000000000 0.118600000000000 0.109100000000000 0.107900000000000 0.216000000000000 0.121100000000000 0.112000000000000 0.110800000000000
0.291200000000000 0.174900000000000 0.163000000000000 0.162000000000000 0.296300000000000 0.197300000000000 0.185500000000000 0.184000000000000 0.313500000000000 0.218600000000000 0.209100000000000 0.207900000000000 0.316000000000000 0.221100000000000 0.212000000000000 0.210800000000000
0.391200000000000 0.274900000000000 0.263000000000000 0.262000000000000 0.396300000000000 0.297300000000000 0.285500000000000 0.284000000000000 0.413500000000000 0.318600000000000 0.309100000000000 0.307900000000000 0.416000000000000 0.321100000000000 0.312000000000000 0.310800000000000
0.491200000000000 0.374900000000000 0.363000000000000 0.362000000000000 0.496300000000000 0.397300000000000 0.385500000000000 0.384000000000000 0.513500000000000 0.418600000000000 0.409100000000000 0.407900000000000 0.516000000000000 0.421100000000000 0.412000000000000 0.410800000000000
0.591200000000000 0.474900000000000 0.463000000000000 0.462000000000000 0.596300000000000 0.497300000000000 0.485500000000000 0.484000000000000 0.613500000000000 0.518600000000000 0.509100000000000 0.507900000000000 0.616000000000000 0.521100000000000 0.512000000000000 0.510800000000000
0.691200000000000 0.574900000000000 0.563000000000000 0.562000000000000 0.696300000000000 0.597300000000000 0.585500000000000 0.584000000000000 0.713500000000000 0.618600000000000 0.609100000000000 0.607900000000000 0.716000000000000 0.621100000000000 0.612000000000000 0.610800000000000
0.791200000000000 0.674900000000000 0.663000000000000 0.662000000000000 0.796300000000000 0.697300000000000 0.685500000000000 0.684000000000000 0.813500000000000 0.718600000000000 0.709100000000000 0.707900000000000 0.816000000000000 0.721100000000000 0.712000000000000 0.710800000000000
0.891200000000000 0.774900000000000 0.763000000000000 0.762000000000000 0.896300000000000 0.797300000000000 0.785500000000000 0.784000000000000 0.913500000000000 0.818600000000000 0.809100000000000 0.807900000000000 0.916000000000000 0.821100000000000 0.812000000000000 0.810800000000000
0.991200000000000 0.874900000000000 0.863000000000000 0.862000000000000 0.996300000000000 0.897300000000000 0.885500000000000 0.884000000000000 1.01400000000000 0.918600000000000 0.909100000000000 0.907900000000000 1.01600000000000 0.921100000000000 0.912000000000000 0.910800000000000
1.09100000000000 0.974900000000000 0.963000000000000 0.962000000000000 1.09600000000000 0.997300000000000 0.985500000000000 0.984000000000000 1.11400000000000 1.01900000000000 1.00900000000000 1.00800000000000 1.11600000000000 1.02100000000000 1.01200000000000 1.01100000000000
1.19100000000000 1.07500000000000 1.06300000000000 1.06200000000000 1.19600000000000 1.09700000000000 1.08600000000000 1.08400000000000 1.21400000000000 1.11900000000000 1.10900000000000 1.10800000000000 1.21600000000000 1.12100000000000 1.11200000000000 1.11100000000000
1.29100000000000 1.17500000000000 1.16300000000000 1.16200000000000 1.29600000000000 1.19700000000000 1.18600000000000 1.18400000000000 1.31400000000000 1.21900000000000 1.20900000000000 1.20800000000000 1.31600000000000 1.22100000000000 1.21200000000000 1.21100000000000];
y_range = logspace(log10(210e-9),log10(100e-6),4);
z_range = logspace(log10(180e-9),log10(100e-6),4);
% Encode data in P and v
% Note: I am pretty sure there are better ways to do this
P = zeros(19*4*4,3);
v = zeros(19*4*4,1);
x_cnt = 1;
y_cnt = 1;
z_cnt = 1;
for i=1:19
for j=1:(4*4)
v(x_cnt,1) = V_matrix(i,j);
P(x_cnt,1) = X_matrix(i,j);
P(x_cnt,2) = y_range(y_cnt);
P(x_cnt,3) = z_range(z_cnt);
x_cnt = x_cnt + 1;
y_cnt = y_cnt + 1;
if(y_cnt>4)
y_cnt = 1;
z_cnt = z_cnt + 1;
if(z_cnt>4)
z_cnt = 1;
end
end
end
end
% Interpolate
F_Veff_ne = scatteredInterpolant(P,v,'natural');
% Visualization
xx = logspace(log10(5e-15),log10(20e-6),20); % This range is slimmer because values above 20e-6 are not of interest.
yy = logspace(log10(210e-9),log10(100e-6),20);
zz = logspace(log10(180e-9),log10(100e-6),20);
[xq,yq,zq] = meshgrid(xx,yy,zz);
min(P), max(P)
[xx(1), yy(1), zz(1)], [xx(end), yy(end), zz(end)]
vq = F_Veff_ne(xq,yq,zq);
nnz(isnan(vq))
scatter3(P(:,1), P(:,2), P(:,3), 30, v)
hold on
colors = [0 1 1; 1 0 0];
cmap = colors(isnan(vq(:))+1,:);
scatter3(xq(:), yq(:), zq(:), 5, cmap, '.')
hold off
xlabel('x'); ylabel('y'); zlabel('z');
xlim(xx([1 end])); ylim(yy([1 end])); zlim(zz([1 end]));
set(gca,'xscale', 'log', 'yscale', 'log', 'zscale', 'log')
The large circles are places where there are data. The small cyan dots are query locations for which interpolation worked. The small red dots are query locations for which interpolation failed.
My interpretation would be that there is a "hole" in the data that 'natural' interpolation is not willing to work around. If you use 'linear' interpolation then you do not get the nans.
2 comentarios
Dominik Hiltbrunner
el 28 de Dic. de 2021
Walter Roberson
el 28 de Dic. de 2021
scatteredInterpolant() warns about problems with data of different magnitudes, and suggests https://www.mathworks.com/help/matlab/math/normalize-data-with-differing-magnitudes.html
Categorías
Más información sobre Interpolation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
