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

조회 수: 2 (최근 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개)

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에서 Smoothing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by