scatteredInterpolant using a matrix, F = scatteredI​nterpolant​(x,y,v) form

6 visualizzazioni (ultimi 30 giorni)
I have some non-uniformly sampled data that I would like to interpolate. I have found the Mathworks article https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html?s_tid=doc_ta and I am attempting to use the scatteredInterpolant in the form Vq = scatteredInterpolant(x,y,v) as shown.
clc;
clear;
Vel = [0; 325; 350; 500; 900; 1200];
AoA = [0; 5; 10; 15; 20; 25];
c = [0, 0, 0, 0, 0, 0;
0.0000, 0.0185, 0.0380, 0.0575, 0.0830, 0.1050;
0.0000, 0.0180, 0.0365, 0.0565, 0.0805, 0.1030;
0.0000, 0.0170, 0.0340, 0.0520, 0.0765, 0.1020;
0.0000, 0.0120, 0.0260, 0.0465, 0.0710, 0.0965;
0.0000, 0.0150, 0.0240, 0.0435, 0.0660, 0.0890];
c_l = scatteredInterpolant(AoA,Vel,c);
Basically each life coefficient, c, corresponds to a sampling at a specific velocity, Vel, and angle of attack, AoA.When I run that code I get the following error:
Error using scatteredInterpolant
Input data point values have invalid dimension. The data must be specified in column-vector format.
However, on the article I linked, it states the following:
Function values at sample points, specified as a vector or matrix. For 2-D data, v = F(x,y). For 3-D data, v = F(x,y,z).
  • To interpolate using a single set of values, specify v as a vector, where the number of rows is the same as the number of sample points.
  • To interpolate using multiple sets of values, specify v as a matrix, where the number of rows is the same as the number of sample points. Each column in v represents the values of a different function at the sample points. For example, if x and y are column vectors with 10 elements, you can specify v as a 10-by-4 matrix to interpolate using four different sets of values.
I'm using c = F(AoA,Vel). AoA is (1,6). Vel is (1,6). c is 6x6. Not sure why it would kick an error saying it has to be a column vector.
Thanks for your time.
  2 Commenti
Stephen23
Stephen23 il 19 Feb 2024
Modificato: Stephen23 il 19 Feb 2024
"Read that article earlier. I attempted griddedInterpolant. I keep throwing an NDGRID error.
Error using griddedInterpolant
Grid arrays must have NDGRID structure."
Better to fix that error message: https://xyproblem.info/
Lets try your supplied data with a gridded interpolant of some kind. Unfortunately your C data has size 6x6 which makes it totally ambiguous which orientation it has relative to the VEL and AOA vectors. I will assume that the 1st dimension is VEL and the 2nd AOA.
Vel = [0; 325; 350; 500; 900; 1200];
AoA = [0; 5; 10; 15; 20; 25];
c = [0, 0, 0, 0, 0, 0;
0.0000, 0.0185, 0.0380, 0.0575, 0.0830, 0.1050;
0.0000, 0.0180, 0.0365, 0.0565, 0.0805, 0.1030;
0.0000, 0.0170, 0.0340, 0.0520, 0.0765, 0.1020;
0.0000, 0.0120, 0.0260, 0.0465, 0.0710, 0.0965;
0.0000, 0.0150, 0.0240, 0.0435, 0.0660, 0.0890];
INTERPN:
[A,B] = ndgrid(Vel,AoA);
interpn(A,B,c,123,23)
ans = 0.0364
GRIDDEDINTERPOLANT:
F = griddedInterpolant(A,B,c);
F(123,23)
ans = 0.0364
It is much better to use gridded interpolation on gridded data.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 19 Feb 2024
Input data point values have invalid dimension. The data must be specified in column-vector format.
This holds when you initially create the interpolant function. When you evaluate it, the arguments can be equal-sized matrices or equal-size vectors.
To use your data with scatteredInterpolant, do this —
Vel = [0; 325; 350; 500; 900; 1200];
AoA = [0; 5; 10; 15; 20; 25];
c = [0, 0, 0, 0, 0, 0;
0.0000, 0.0185, 0.0380, 0.0575, 0.0830, 0.1050;
0.0000, 0.0180, 0.0365, 0.0565, 0.0805, 0.1030;
0.0000, 0.0170, 0.0340, 0.0520, 0.0765, 0.1020;
0.0000, 0.0120, 0.0260, 0.0465, 0.0710, 0.0965;
0.0000, 0.0150, 0.0240, 0.0435, 0.0660, 0.0890];
[Velm,AoAm] = ndgrid(Vel, AoA);
F = scatteredInterpolant(Velm(:), AoAm(:), c(:)); % Use the '(:)' Convention To Create Column Vectors
Velv = linspace(min(Vel), max(Vel), 30); % Evaluate At Finer Grid Points
AoAv = linspace(min(AoA), max(AoA), 30);
[Velmq,AoAmq] = ndgrid(Velv,AoAv);
C = F(Velmq,AoAmq);
cline1 = F(Velv, AoAv); % Calculate Simple Line On The Surface
figure
surf(Velmq, AoAmq, C)%, 'FaceAlpha',0.5)
colormap(turbo)
xlabel('Velocity')
ylabel('Angle of Attack')
zlabel('c')
hold on
plot3(Velv, AoAv, cline1, '-m', 'LineWidth',2) % Draw Line On The Surface
hold off
view(-15,30)
If your data are gridded, scatteredInterpolant may initially seem to be excessive, however if you want to draw lines on the surface or do other detailed approximations on the interpolated data, it is (in my experience at least) the best option.
.
  2 Commenti
Stephen23
Stephen23 il 19 Feb 2024
Modificato: Stephen23 il 19 Feb 2024
"however if you want to draw lines on the surface or do other detailed approximations on the interpolated data, it is (in my experience at least) the best option."
Could you explain some specific reasons why you found that to be the "best option" ? Given that the query points can be arrays of any size, I am surprised that it makes any difference (from the query-point perspective).
Vel = [0; 325; 350; 500; 900; 1200];
AoA = [0; 5; 10; 15; 20; 25];
c = [0, 0, 0, 0, 0, 0;
0.0000, 0.0185, 0.0380, 0.0575, 0.0830, 0.1050;
0.0000, 0.0180, 0.0365, 0.0565, 0.0805, 0.1030;
0.0000, 0.0170, 0.0340, 0.0520, 0.0765, 0.1020;
0.0000, 0.0120, 0.0260, 0.0465, 0.0710, 0.0965;
0.0000, 0.0150, 0.0240, 0.0435, 0.0660, 0.0890];
[Velm,AoAm] = ndgrid(Vel, AoA);
F = griddedInterpolant(Velm,AoAm,c); % more efficient gridded interpolant
Velv = linspace(min(Vel), max(Vel), 30); % Evaluate At Finer Grid Points
AoAv = linspace(min(AoA), max(AoA), 30);
[Velmq,AoAmq] = ndgrid(Velv,AoAv);
C = F(Velmq,AoAmq);
cline1 = F(Velv, AoAv); % Calculate Simple Line On The Surface
figure
surf(Velmq, AoAmq, C)%, 'FaceAlpha',0.5)
colormap(turbo)
xlabel('Velocity')
ylabel('Angle of Attack')
zlabel('c')
hold on
plot3(Velv, AoAv, cline1, '-m', 'LineWidth',2) % Draw Line On The Surface
hold off
view(-15,30)
Star Strider
Star Strider il 19 Feb 2024
The scatteredInterpolant function works best for those problems in my experience. I’ve used the others, and they’ve not given equivalently accurate results, even for problems such as this.

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by