How can I interpolate time?

20 ビュー (過去 30 日間)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2021 年 11 月 8 日
コメント済み: Star Strider 2021 年 11 月 9 日
Hello everyone.
I have a vector with times called
tim1_1
, of size 51*1, I also have measurements called
lam1_1
made at those times.
tim1_1
goes between 0 and 1.737857815507103e+03. Instead of 51 measurements I want to have an arbitrary number, let's say 200. I have tried to write
interpLam1_1R = interp1(tim1_1,lam1_1,1:tim1_1(end)/200:tim1_1(end),'spline');
Unfortunately, if I plot the obtained results, they don't look like the original ones at all. As can be seen in the attached figure, the original data (in blue) looks almost sinusoidal,meanwhile, the interpolated data looks almost as a straight line.
Can someone please help me with this problem?

採用された回答

Star Strider
Star Strider 2021 年 11 月 8 日
Apparently ‘tim1_1’ is not a datetime array.
tim1_1 = linspace(0, 1.737857815507103e+03, 51);
lam_1 = sin(2*pi*1E-3*tim1_1);
tim1_2 = linspace(min(tim1_1), max(tim1_1), 200);
lam_1_2 = interp1(tim1_1, lam_1, tim1_2);
figure
plot(tim1_1, lam_1, '.b')
hold on
plot(tim1_2, lam_1_2, '.r')
hold off
grid
legend('Original','Interpolated', 'Location','best')
Experiment to get different results.
.
  2 件のコメント
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2021 年 11 月 9 日
Thanks, I think I can work with this.
Star Strider
Star Strider 2021 年 11 月 9 日
As always, my pleasure!
.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by