[英]smoothing 2D plot in MATLAB
I have some simple plot like this in MATLAB: 我在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 也许您可以如下使用
spline
x1 = 0:.1:25;
y1 = spline(x,y,x1);
plot(x,y,x1,y1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.