how do you make an interpolation such that it interpolates the value betwee the first and the last array entry?

5 次查看(过去 30 天)
I have a position array from 0 to 100 (with corresponding values in a separate array) and I have calculated some query points, the first one being at -0.15. Of course this is outside the range of which interpolation is possible, however, the problem I am solving is strictly periodic. This means that extrapolating below zero is the same as interpolating between the the first and the last entry of the value-array (between zero and 100). How can modify my program such that I can accommodate this periodicity?

回答(1 个)

Les Beckham
Les Beckham 2017-6-9
IF you are saying that the 'position = 100' value is the same as the 'position = 0' value then you can just do a modulo 100 on the input position value before you do the interpolation. For your example:
>> mod(-0.15, 100)
ans =
99.8500
So, interpolating with the mod result would give you the same answer as if you interpolated with 99.85.
If my assumption is not correct (e.g., the 'position = 100' value is actually the same as the unspecified 'position = -1' value) you would need to tweak this approach. Maybe just append a copy of the 'position = 0' value as 'position = 101' and modulo with 101. You will have to add a 101 entry to your position vector (the x for interp1) as well.
I hope that this helps.
  1 个评论
John D'Errico
John D'Errico 2017-6-10
Moved to a comment from Ulla:
"Thanks so much for your answer.
It would solve my problem if it was as simple as that. The problem is the interpolation calculation is in a loop, so I calculate different query points every loop. sometimes, it's negative in the first input, other times it's not, sometimes it's beyond 100 in the last time step, other times it is not.
Is there a way to make sure that anything below zero or above 100 is interpreted as just the pattern repeating?"

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by