フィルターのクリア

Error: EXTRAPVAL must be a scalar

29 ビュー (過去 30 日間)
Jing Ci Neo
Jing Ci Neo 2020 年 7 月 27 日
コメント済み: Jing Ci Neo 2020 年 7 月 29 日
I want to interpolate and extrapolate my matrix using interp2. Why am I getting the error "EXTRAPVAL must be a scalar"?
Below is my code, n and m are integers and C is an m by n matrix.
[X,Y] = meshgrid(0.5:n-0.5,0.5:m-0.5);
[Xq,Yq] = meshgrid(0:n,0:m);
slip=interp2(X,Y,C,Xq,Yq,'linear','extrapval');

採用された回答

Stephen23
Stephen23 2020 年 7 月 27 日
編集済み: Stephen23 2020 年 7 月 27 日
According to the interp2 documentation, the extrapval must be a scalar numeric:
A character vector is not supported. Only a scalar constant value is supported.
If you expect the extrapolation to calculate some value then you will need to either:
  3 件のコメント
Stephen23
Stephen23 2020 年 7 月 27 日
編集済み: Stephen23 2020 年 7 月 27 日
"what can interp2 exrapolate then?"
That depends on how you call it:
  • When you provide the extrapval input argument then interp2 only extrapolates with that one fixed, constant numeric value. For example, if you provide the value 5, then all extrapolated data will have the value 5. By providing that argument you tell interp2 to not extrapolate using any interpolation method.
  • If you do not specify extrapval then it will extrapolate for some of the interpolation methods, the documentation clearly lists which ones, otherwise it will return NaN. Just as the documentation states.
"What character vector are you referring to?"
slip=interp2(X,Y,C,Xq,Yq,'linear','extrapval');
% ^^^^^^^^^^^ this one
You provided a char vector, which is not a valid input. A valid input is a real scalar of class single or double.
Jing Ci Neo
Jing Ci Neo 2020 年 7 月 29 日
Thanks Stephen!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by