简体   繁体   中英

smoothing 2D plot in MATLAB

I have some simple plot like this in MATLAB:

x = [0:5:25];
y = [1 4 7 9 8 3];
plot(x,y)

My question is how can I smooth it? Haven't found any way of doing what I want in documentation.

You can use a cubic smoothing spline

p  = 1e-2;           % initialize smoothing constant
fn = csaps(x, y, p); % get ppform of the cubic smoothing spline
y1 = ppval(fn, x);   % evaluate piecewise polynomial

For comparison:

plot(x,y);
hold on;
plot(x, y1, '-r');

Maybe you could make use of spline as follows

x1 = 0:.1:25;
y1 = spline(x,y,x1);
plot(x,y,x1,y1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM