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

2 次查看(过去 30 天)
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 个)

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 CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by