plotting X and Y coordinates over time
42 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have a data containing X and Y coordinates which I'd like to plot them over fixed time intervals. I tried to use linear interpolation but it doesn't work. Can anyone help me with this please.
Xp = [1:0.25:50693];
yp =interp1(X,Y,Xp,'linear');
figure
plot(X,Y,'o');
hold on
plot(Xp,yp,'r-');
xlabel('X');
ylabel('Y');
title('X and Y positions')
grid on
3 comentarios
Dyuman Joshi
el 31 de Jul. de 2022
Are there any repeating values in your data? That causes the error
X=[1 1 2 3 4 5 5]; %repeating values
Y=[2 3 4 5 6 7 8];
%you can check with repeating values in Y as well, it will give the same error
Xp=1:0.25:2.5;
Yp =interp1(X,Y,Xp,'linear')
Respuestas (1)
Star Strider
el 31 de Jul. de 2022
Editada: Star Strider
el 31 de Jul. de 2022
The data were not supplied, however it quite probably works correctly. You are asking it to do a linear interpolation, probably to a finer ‘x’ resolution, and it does exactly that.
The plots would appear to be the same because the method chosen is 'linear'. If you chose a different interpolation method, the plots might appear to be different.
EDIT — (31 Jul 2022 at 17:30)
To make the sample points unique:
X = sort(randi(50,100,1))
Y = randi(90, 100, 1)
[Ux,i1] = unique(X)
X = Ux;
Y = Y(i1);
Xp = [1:0.25:50693];
yp =interp1(X,Y,Xp,'linear');
figure
plot(X,Y,'o');
hold on
plot(Xp,yp,'r-');
xlabel('X');
ylabel('Y');
title('X and Y positions')
grid on
It would help to have the actual data, however this illustrates the concept.
.
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!