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 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