2d interpolation of n-dimensional data

1 回表示 (過去 30 日間)
Curtis Wen
Curtis Wen 2021 年 8 月 24 日
コメント済み: Curtis Wen 2021 年 8 月 25 日
I have this set of data (simplified)
x = [1 2 3]
y = [3 7 2]
temp = [22 25 23; 33 25 17; 19 25 26];
each X Y coordinate pair corresponds to a column in temp. So (X,Y) = (1,3) -> [22; 33; 19]. I'm trying to setup a 2D interpolation which gives me interpolated values of temp from input XY. My solution which works, but is slow, is to create a scatteredinterpolant for every row of temp ie
int1 = scatteredinterpolant([1 2 3]', [3 7 2]', [22 25 23]')
int2 = scatteredinterpolant([1 2 3]', [3 7 2]', [33 25 17]')
int3 = scatteredinterpolant([1 2 3]', [3 7 2]', [19 25 26]')
and then using the scatteredinterpolants 3 times. My actual dataset of temp has 30000 elements per coordinate pair, so this goes pretty slow. Any suggestions?

採用された回答

Sean de Wolski
Sean de Wolski 2021 年 8 月 24 日
You can just change the Values of one scatteredInterpolant object. It won't have to redo the expensive underlying triangulation of x/y then. Example using zeros and ones for your temp.
s = scatteredInterpolant(rand(3,1),rand(3,1),zeros(3,1))
s =
scatteredInterpolant with properties: Points: [3×2 double] Values: [3×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
s(0.3,0.2)
ans = 0
s.Values = ones(3,1) % swap for your second set of values
s =
scatteredInterpolant with properties: Points: [3×2 double] Values: [3×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
s(0.3,0.2)
ans = 1
  1 件のコメント
Curtis Wen
Curtis Wen 2021 年 8 月 25 日
Its not too much of a time savings since the evaluation of each interp still takes as long, but it does reduce the number of interpolant objects created and reduces my filesize so I'll take it. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by