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

3 Ansichten (letzte 30 Tage)
liv_ped
liv_ped am 25 Mär. 2019
Kommentiert: liv_ped am 25 Mär. 2019
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?

Akzeptierte Antwort

Kevin Phung
Kevin Phung am 25 Mär. 2019
Bearbeitet: Kevin Phung am 25 Mär. 2019
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.

Weitere Antworten (1)

dpb
dpb am 25 Mär. 2019
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...

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by