Error in function interp1: Sample points must be unique.

I am running multiple patient files in my matlab script. These files are all the same, however, by just one file I get this error:
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
My script around this error is as following:
tv_interval = tv_before - polyval(coef_tv, time_interval);
rf_interval = rf_before - polyval(coef_rf, time_interval);
ve_interval = ve_before - polyval(coef_ve, time_interval);
ti_interval = ti_before - polyval(coef_ti, time_interval);
te_interval = te_before - polyval(coef_te, time_interval);
new_time = transpose([0:1:time_interval(end)]);
tv_interval = interp1(time_interval, tv_interval,new_time);
rf_interval = interp1(time_interval, rf_interval,new_time);
ve_interval = interp1(time_interval, ve_interval,new_time);
Thanks!

回答 (2 件)

Torsten
Torsten 2022 年 6 月 29 日
編集済み: Torsten 2022 年 6 月 29 日

1 投票

You can use unique() to get rid of duplicate sample points. It will also sort them.

2 件のコメント

Marthe Westerbroek
Marthe Westerbroek 2022 年 6 月 29 日
But wont this influence the results? I use this interpolation to calculate the iqr. Can I still do that ?
Torsten
Torsten 2022 年 6 月 29 日
If you use interp1 as
yq = interp1(x,y,xq)
the vector x must contain unique values and must be sorted in descending or ascending order.
Further
min x <= xq <= max x
should be true.
Are these conditions satisfied in your application ?

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

Star Strider
Star Strider 2022 年 6 月 29 日

0 投票

I looked through the code, however I do not see that you ever actually created a timetable object (introduced in R2016b). The best option will likely be to do tthat, and then use the retime function to do the time interpolation (that appears to be what you want to do, although I cannot determine that definitively).
Contents of ‘test_7_newinterval.m’
url = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1049880/test_7_newinterval.m';
opts = weboptions('ContentType','text');
W = webread(url, opts)
.

2 件のコメント

Marthe Westerbroek
Marthe Westerbroek 2022 年 6 月 29 日
Okay, thank you!
Star Strider
Star Strider 2022 年 6 月 29 日
My pleasure!

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

カテゴリ

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

質問済み:

2022 年 6 月 29 日

コメント済み:

2022 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by