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 日

1 投票

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 ExchangeInterpolation についてさらに検索

タグ

質問済み:

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