Interpolate 2D-lookup table
15 views (last 30 days)
Show older comments
Andreas Moser
on 22 Sep 2020
Commented: Ameer Hamza
on 24 Sep 2020
I have several curves, which describe the stiffness of a tire over the load at seven different tire pressures. Now I`m want to make a function, which interpolates between the measured data and can return the stiffness at a specific load and tire pressure. I tried the 'interp2'-function, but got the following error message:
'Error using interp2>makegriddedinterp (line 237)
Input grid is not a valid MESHGRID.'
Here is an example of my code:
close all, clear all, clc
% load [kg]
m = [
1800 2500 3200 3900 4700;
2300 3300 4250 5300 6300;
2900 4100 5300 6500 7800;
3400 4800 6200 7600 9100;
3700 5100 6600 8200 9800
];
% tire pressure [bar]
p = [
1.6 1.6 1.6 1.6 1.6;
2.4 2.4 2.4 2.4 2.4;
3.2 3.2 3.2 3.2 3.2;
4.0 4.0 4.0 4.0 4.0;
4.4 4.4 4.4 4.4 4.4;
];
% stiffness [DaN/mm]
c = [
43 45 47 48 49
58 61 63 65 66
71 74 77 80 82
84 88 91 94 96
90 94 97 100 102
];
% 3D-Plot
[mq, pq] = meshgrid(0:100:10000, 0:0.05:5);
cq = interp2(m, p, c, mq, pq);
figure;
surf(mq, pq, cq);
1 Comment
John D'Errico
on 22 Sep 2020
Edited: John D'Errico
on 22 Sep 2020
The array m is NOT an array that meshgrid would produce.
Therefore, you cannot use interp2.
It is also true that you will be doing some serious, significant extrapolation. So expect poor results in those regions.
Accepted Answer
Ameer Hamza
on 22 Sep 2020
Edited: Ameer Hamza
on 22 Sep 2020
Since your data is not available as meshgrid, you need to use scatteredInterpolant()
% load [kg]
m = [
1800 2500 3200 3900 4700;
2300 3300 4250 5300 6300;
2900 4100 5300 6500 7800;
3400 4800 6200 7600 9100;
3700 5100 6600 8200 9800
];
% tire pressure [bar]
p = [
1.6 1.6 1.6 1.6 1.6;
2.4 2.4 2.4 2.4 2.4;
3.2 3.2 3.2 3.2 3.2;
4.0 4.0 4.0 4.0 4.0;
4.4 4.4 4.4 4.4 4.4;
];
% stiffness [DaN/mm]
c = [
43 45 47 48 49
58 61 63 65 66
71 74 77 80 82
84 88 91 94 96
90 94 97 100 102
];
mv = m(:);
pv = p(:);
cv = c(:);
model = scatteredInterpolant(mv, pv, cv);
[mq, pq] = meshgrid(0:100:10000, 0:0.05:5);
cq = model(mq, pq);
surf(mq, pq, cq);
shading interp
hold on
plot3(mv, pv, cv, 'r+', 'MarkerSize', 5, 'LineWidth', 2);

As John mentioned, there is quite a lot of extrapolation. However, the data points seem like lying on a plane; it might not be an issue. It depends on you if these values are acceptable.
3 Comments
Ameer Hamza
on 24 Sep 2020
Because your data is not available as a mesh grid. Matrix m has different elements in each column. For it to be a mesh grid, the column entries must be the same. My code has created mesh grids, you can apply interp2 on mq, pq, and cq.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!