Smoothing curve plot with some data points

조회 수: 11 (최근 30일)
Smithy
Smithy 2022년 12월 21일
댓글: Smithy 2022년 12월 21일
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