Hi
I want to interpolate between two arrays.
My cell is, scale_x = {...
0 ,0,0.009,0.035,0.04,0.1;...
10 ,0,0.02,0.04,0.15,0.2;...
30 ,0,0.08,0.09,0.12,0.2;...
40 ,0,0.02,0.01,0.06,0.2;...
50 ,0,0.05,0.08,0.1,0.2;...
60 ,0,0.02,0.05,0.06,0.15;...
70 ,0,0.005,0.013,0.05,0.1;...
80 ,0,0.001,0.01,0.02,0.1;...
90 ,0,0.005,0.04,0.08,0.2;...
100 ,0,0.001,0.008,0.01,0.08;...
110 ,0,0.003,0.01,0.04,0.2;...
130,0,0.01,0.01,0.04,0.2;...
};
The first column of the variable denote the vehicle speed. The rest of the columns are data related to theat vehicle speed.
So when i get an input of vehicle speed which is inbetween two vehicle speeds, I want to interpolate between that two rows.
For example, say that my input speed is 48. It is between 40 and 50. So, i get the two rows as two arrays.
Say, x1 = [40 0 0.02 0.01 0.06 0.2] x2 = [50 0 0.05 0.08 0.1 0.2]. Now i have to interpolate both arrays for the value 48. Is my idea to do the interpolation correct? Or is there any way to do it directly without gettin the rows as arryas? I was not able to do it. Help me with this.

 채택된 답변

DGM
DGM 2021년 7월 8일
편집: DGM 2021년 7월 8일
I don't know why you're using a cell array for this unless you just really like making everything harder. Just use a numeric array and interpolate.
scale_x = [ 0 ,0,0.009,0.035,0.04,0.1;...
10 ,0,0.02,0.04,0.15,0.2;...
30 ,0,0.08,0.09,0.12,0.2;...
40 ,0,0.02,0.01,0.06,0.2;...
50 ,0,0.05,0.08,0.1,0.2;...
60 ,0,0.02,0.05,0.06,0.15;...
70 ,0,0.005,0.013,0.05,0.1;...
80 ,0,0.001,0.01,0.02,0.1;...
90 ,0,0.005,0.04,0.08,0.2;...
100 ,0,0.001,0.008,0.01,0.08;...
110 ,0,0.003,0.01,0.04,0.2;...
130,0,0.01,0.01,0.04,0.2]
scale_x = 12×6
0 0 0.0090 0.0350 0.0400 0.1000 10.0000 0 0.0200 0.0400 0.1500 0.2000 30.0000 0 0.0800 0.0900 0.1200 0.2000 40.0000 0 0.0200 0.0100 0.0600 0.2000 50.0000 0 0.0500 0.0800 0.1000 0.2000 60.0000 0 0.0200 0.0500 0.0600 0.1500 70.0000 0 0.0050 0.0130 0.0500 0.1000 80.0000 0 0.0010 0.0100 0.0200 0.1000 90.0000 0 0.0050 0.0400 0.0800 0.2000 100.0000 0 0.0010 0.0080 0.0100 0.0800
% idk what output you want, so this just returns the whole row for a query velocity
thisv = [5 45];
thisrow = interp1(scale_x(:,1),scale_x,thisv)
thisrow = 2×6
5.0000 0 0.0145 0.0375 0.0950 0.1500 45.0000 0 0.0350 0.0450 0.0800 0.2000

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2021년 7월 8일

댓글:

2021년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by