필터 지우기
필터 지우기

ploting coordinate smoothly with given dataset

조회 수: 2 (최근 30일)
Jiung Shin
Jiung Shin 2020년 12월 8일
댓글: Cris LaPierre 2020년 12월 8일
I want to draw the position of the object using vector x and y each containing coordinate of x and y with change in time.
To make the movement smooth using least square fitting, I p=polyval(x,y,60) and it returns:
Warning: Polynomial is badly
conditioned. Add points with distinct X
values, reduce the degree of the
polynomial, or try centering and scaling
as described in HELP POLYFIT.
the dataset is given so I can't change it. Please help

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 12월 8일
편집: Cris LaPierre 2020년 12월 8일
I think you meant to use polyfit instead of polyval.
However, an n of 60 is a bit ridiculous. I would strongly recommend picking a value that is more appropriate for your data. At an absolute minimum, n cannot be great than your number of points. It should actually be much less than your number of points. Otherwise, you risk overfitting.
  댓글 수: 2
Jiung Shin
Jiung Shin 2020년 12월 8일
in my data set, it is listed in order of time but the x coordinate goes back and forth and sometimes overlap so while plot(x,y) shows a rough circlular shape, the polyfit only shows function going in one direction.
If my purpose is to smooth the circular shape, which tool should I use?
Cris LaPierre
Cris LaPierre 2020년 12월 8일
Unfortunately, I'm not aware of a good technique for smoothing data that is not a function (vertical line test).
I'm just googling here, but a couple options might be
% Circle points
x=10*cos(0:.07:6*pi);
y=10*sin(0:.07:6*pi);
% Add noise
x=x+rand(size(x))-.5;
y=y+rand(size(x))-.5;
plot(x,y,'.')
axis equal
xlim([-12 12])
ylim([-12 12])
% S-G filtering
windowWidth = 35;
polynomialOrder = 2;
smoothX = sgolayfilt(x, polynomialOrder, windowWidth);
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
hold on
plot(smoothX,smoothY,'or')
hold off
  • Use the smooth function (data likely has to be in order. Could use sort/sortrows for that)
smoothX1 = smooth(x);
smoothY1 = smooth(y);
hold on
plot(smoothX1,smoothY1,'*g')
hold off

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by