フィルターのクリア

interp1 - problem with query points

4 ビュー (過去 30 日間)
Maria
Maria 2019 年 8 月 9 日
コメント済み: Star Strider 2019 年 8 月 12 日
Hi,
I am facing a really strange behavior of the function interp1.
I have the variables in the file .mat in attachment, where x is a vector , f is a matrix, and delta is a vector that is computed somewhere else in the code .
From the command windows, I can see that
>> delta =
0.5000 0 0
I am confused because the first value of delta gives me NaN, but not if I simply interpolate directly for 0.5 (what I believe is the value of delta(1) !)
>> f_interp = interp1(x,f,delta(1))
f_interp =
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
>> f_interp = interp1(x,f,0.5)
f_interp =
Columns 1 through 15
0.9882 0.9882 0.9984 1.0221 1.0389 1.0482 1.0843 1.1814 1.2525 1.3288 1.3961 1.5075 1.6173 1.6866 1.7918
Columns 16 through 21
1.8649 1.8835 1.9232 1.9819 2.0135 2.0371
I am assuming that this result has something to do with how the numbers are stored in delta. In fact, if I manually assign
delta(1) = 0.5;
then it works. So this problem has to do with how the number is stored in the vector, and not with the vector itself.
How can I figure out what is wrong with the stored number? Can anyone help?

採用された回答

Star Strider
Star Strider 2019 年 8 月 9 日
You have encountered ‘floating-point approximation error’. If you subtract ‘delta(1)’ from ‘x’:
Check = x-delta(1)
the result is:
Check =
-5.000000000000001e-01
-4.800000000000001e-01
-4.500000000000001e-01
-4.000000000000001e-01
-3.000000000000001e-01
-1.110223024625157e-16
so you are asking interp1 to extrapolate, without telling it how.
This worked when I tried it:
f_interp = interp1(x,f,delta(1), 'linear','extrap');
and produced a numeric vector with no NaN values.
  2 件のコメント
Maria
Maria 2019 年 8 月 12 日
Thank you! I thought was something like that, so I tried to use the "long" format to see whether there was some last "1" that I could not see, but it did not help.
Star Strider
Star Strider 2019 年 8 月 12 日
As always, my pleasure!
The long format is the correct appproach, however it’s best to see the difference, so using the long format with subtraction provides the necessary information.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by