Smoothing curve plot with some data points

11 次查看(过去 30 天)
hello, everybody
I have these data and I hope to plot them with smooth line.
Is it possible to create a smooth curve through these data points? I tried polybuffer function and it looks better.
But for data smoothing I failed using interpolation due to drastic chanhge of data points.
However, I think there is some ways I think. If possible please help me some.
x = [-27.59;-32.36;-32.36;-24.99;-25.12;-32.62;-37.62;-42.62;-37.62;-37.62;-40.11;-40.11;-37.61;-33.36;-29.11;-27.11;-25.11;-20.61;-14.36;15.64;45.64;158.76];
y = [-16.55;-16.55;-16.55;-16.62;-16.69;-16.69;-25.44;-34.19;-51.69;-51.69;-42.98;-42.98;-51.73;-60.48;-69.23;-70.48;-71.73;-81.73;-104.23;-126.73;-149.23;-149.23];
pgon = polybuffer([x y],'lines',2);
plot(pgon,'FaceColor','r','FaceAlpha',1,'EdgeColor','none')
% plot(x,y)

采纳的回答

Jonas
Jonas 2022-12-21
x = [-27.59;-32.36;-32.36;-24.99;-25.12;-32.62;-37.62;-42.62;-37.62;-37.62;-40.11;-40.11;-37.61;-33.36;-29.11;-27.11;-25.11;-20.61;-14.36;15.64;45.64;158.76];
y = [-16.55;-16.55;-16.55;-16.62;-16.69;-16.69;-25.44;-34.19;-51.69;-51.69;-42.98;-42.98;-51.73;-60.48;-69.23;-70.48;-71.73;-81.73;-104.23;-126.73;-149.23;-149.23];
subplot(1,2,1);
scatter(x,y,'ko')
hold on;
% you can try to use a sgolay filter directly on the data
smoothx=smooth(x,'sgolay');
smoothy=smooth(y,'sgolay');
plot(smoothx, smoothy)
dx=diff(x);
dy=diff(y);
factor=5;
interpx=cumsum([x(1); repelem(dx/factor,factor)]);
interpy=cumsum([y(1); repelem(dy/factor,factor)]);
% or you do some interpolation before to generate more point and change the
% parameters of the smooth function as needed
smoothx=smooth(interpx,15,'sgolay',2);
smoothy=smooth(interpy,15,'sgolay',2);
subplot(1,2,2)
scatter(x,y,'ko')
hold on;
scatter(interpx,interpy,'r.');
plot(smoothx, smoothy)
linkaxes()
  1 个评论
Smithy
Smithy 2022-12-21
Wow, Thank you very much. It works really well. I really really appreciate with it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Smoothing 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by