How to do cubic interpolation from given sets of data ?

5 ビュー (過去 30 日間)
Herp Derp
Herp Derp 2017 年 2 月 19 日
コメント済み: Star Strider 2017 年 2 月 19 日
I'm new to matlab. I'm trying to learn how to do cubic interpolation from given sets of data for example x=[0 1 8 12 27] and y=[1 2 3 4 5] I know matlab has some functions that do cubic interpolation but I don't understand how to to implement them with data sets. I've tried using references from the site and other sources but I can't seem to find any guidance for this.

採用された回答

Star Strider
Star Strider 2017 年 2 月 19 日
The interp1 function with the 'pchip' method is the easiest way to do this (for me, anyway).
From the documentation:
  • 'pchip' Shape-preserving piecewise cubic interpolation.
The Code
x=[0 1 8 12 27];
y=[1 2 3 4 5];
xi = linspace(min(x), max(x));
yi = interp1(x, y, xi, 'pchip');
figure(1)
plot(xi, yi)
hold on
plot(x, y, 'pr', 'MarkerFaceColor','g')
hold off
grid
  4 件のコメント
Herp Derp
Herp Derp 2017 年 2 月 19 日
I'm a bit new to this topic. If they are both suppose to do cubic spline interpolations why are their graphs different ?
Star Strider
Star Strider 2017 年 2 月 19 日
They’re not all ‘cubic spline’ interpolations. I wasn’t clear on what you intended by ‘cubic interpolation’. This now covers every option I can find.
The spline function will give the same result with interp1 with the 'spline' method:
x=[0 1 8 12 27];
y=[1 2 3 4 5];
xi = linspace(min(x), max(x));
yi = interp1(x, y, xi, 'spline');
figure(1)
plot(xi, yi)
hold on
plot(x, y, 'pr', 'MarkerFaceColor','g')
hold off
grid

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

その他の回答 (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