How do I make a smooth curve using the following data?

8 ビュー (過去 30 日間)
liv_ped
liv_ped 2019 年 3 月 25 日
コメント済み: liv_ped 2019 年 3 月 25 日
x1 = {0,0.0521,0.1042, 0.1563, 0.2083, 0.2604, 0.3125, 0.3646, 0.4167}
y1 = {2.4015, 2.9473, 4.5847, 5.7855, 7.4229, 9.6061, 12.2259, 13.2083, 13.6450}
x2 = {0, 0.0510, 0.1020, 0.1531, 0.2041, 0.2551}
y2 = {1.6836, 2.3150, 3.2620, 3.9986, 4.9456, 6.8397}
plot(x1,y1,x2,y2) _____________This function gives a rough curve.
How do I plot this data in the form of a smooth curve and show all the discrete points?

採用された回答

Kevin Phung
Kevin Phung 2019 年 3 月 25 日
編集済み: Kevin Phung 2019 年 3 月 25 日
figure
x1 = [0,0.0521,0.1042, 0.1563, 0.2083, 0.2604, 0.3125, 0.3646, 0.4167];
x1q = linspace(x1(1),x1(end),100);
y1 = [2.4015, 2.9473, 4.5847, 5.7855, 7.4229, 9.6061, 12.2259, 13.2083, 13.6450];
y1q = interp1(x1,y1,x1q,'pchip');
x2 = [0, 0.0510, 0.1020, 0.1531, 0.2041, 0.2551];
x2q = linspace(x2(1),x2(end),100);
y2 = [1.6836, 2.3150, 3.2620, 3.9986, 4.9456, 6.8397];
y2q = interp1(x2,y2,x2q,'pchip');
plot(x1q,y1q,'r',x2q,y2q,'b')
hold on
plot(x1,y1,'ro',x2,y2,'bo')
let me know if this is what you wanted. I suggest reading up interpolation in the documentation.
  1 件のコメント
liv_ped
liv_ped 2019 年 3 月 25 日
Yes this works. Thanks!

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

その他の回答 (1 件)

dpb
dpb 2019 年 3 月 25 日
Presuming you first convert your data to arrays from cell array...
plot(x1,y1,'x',x2,y2,'s') % plot the data only
X1=linspace(x1(1),x1(end)); % get a bunch of points between existing end points
Y1=interp1(x1,y1,X1,'spline'); % one of many possible interpolation choices that goes thru points
hold on
plot(linspace(x1(1),x1(end)),Y1,'b-');
...
Extension to second should be obvious...

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by