Azzera filtri
Azzera filtri

ploting coordinate smoothly with given dataset

2 visualizzazioni (ultimi 30 giorni)
Jiung Shin
Jiung Shin il 8 Dic 2020
Commentato: Cris LaPierre il 8 Dic 2020
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

Risposte (1)

Cris LaPierre
Cris LaPierre il 8 Dic 2020
Modificato: Cris LaPierre il 8 Dic 2020
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 Commenti
Jiung Shin
Jiung Shin il 8 Dic 2020
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 il 8 Dic 2020
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

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by