Interpolate 2D-lookup table

15 ビュー (過去 30 日間)
Andreas Moser
Andreas Moser 2020 年 9 月 22 日
コメント済み: Ameer Hamza 2020 年 9 月 24 日
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 Center および File Exchange2-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