Interpolate 2D-lookup table

18 次查看(过去 30 天)
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 个评论
John D'Errico
John D'Errico 2020-9-22
编辑:John D'Errico 2020-9-22
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.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-9-22
编辑:Ameer Hamza 2020-9-22
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 个评论
Andreas Moser
Andreas Moser 2020-9-24
Thanks for your quick answers, that`s what I wanted. But can you explain, why interp2 doesn´t work?
Ameer Hamza
Ameer Hamza 2020-9-24
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by