how to use interp1() function with half data

x=half(0:5);
y=x.^2;
interp1(x,y,5)
Error using matlab.internal.math.interp1
Sample values must be of type double or single.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
How to use interpolation with half or even shorter types?

 採用された回答

Sam Chak
Sam Chak 2025 年 6 月 5 日

1 投票

Hi @li, If you double the data, it works.
x=half(0:5)
x = 1×6 half row vector 0 1 2 3 4 5
y=x.^2
y = 1×6 half row vector 0 1 4 9 16 25
interp1(double(x), double(y), 5)
ans = 25

4 件のコメント

li
li 2025 年 6 月 5 日
Thanks.Due to the lower memory, the data inputted must smaller than 16bits,so doubled the data can't solve the probelm.
Sam Chak
Sam Chak 2025 年 6 月 5 日
Hi @li
I see. Could you possibly perform the interpolation in another system and then transmit the interpolated data back in 16-bit format? I am merely exploring the possibilities.
If all else fails, you may need to perform the interpolation using basic arithmetic operators. I have verified that the plus, minus, times, and rdivide functions can handle int16 data.
li
li 2025 年 6 月 5 日
Great! I had tried your method,it works.
Matt J
Matt J 2025 年 6 月 5 日
@li If so, please Accept-click the answer.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

li
2025 年 6 月 5 日

コメント済み:

2025 年 6 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by