How to extrapolate the first 5 points
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
attached is an array of points that I have. When I use scatter plot to graph those points, I see that the first 5 points are not aligned. Does anyone know how to extrapolate those points to be aligned with the rest correctly- only by using the points that are aligned "points(6:end,:)". Thanks so much.
Risposte (4)
Torsten
il 8 Nov 2023
Modificato: Torsten
il 8 Nov 2023
p = load("points.mat");
px = p.points(:,1);
py = p.points(:,2);
[~,idx] = sort(px);
px = px(idx);
py = py(idx);
plot(px,py)
Another solution:
p = load("points.mat");
px = p.points(:,1);
py = p.points(:,2);
for i = 1:4
py(i) = interp1(px(5:end),py(5:end),px(i));
end
[~,idx] = sort(px);
px = px(idx);
py = py(idx);
plot(px,py)
0 Commenti
John D'Errico
il 8 Nov 2023
Modificato: John D'Errico
il 8 Nov 2023
load points.mat
x = points(:,1);
y = points(:,2);
i1 = 1:5;
i2 = 6:336;
plot(x(i1),y(i1),'ro',x(i2),y(i2),'g.')
I have no idea what you mean by extrapolation. The red points are essentially contained within the realm of the green ones.
Do you wish to INTERPOLATE the red points, essentially choosing new y values at each x location, so the red points now fall on the curve of the green ones? That is trivial. Just use interp1.
0 Commenti
Les Beckham
il 8 Nov 2023
Modificato: Les Beckham
il 8 Nov 2023
load points.mat
plot(points(:,1), points(:,2), '.-');
grid on
figure
plot(points(:,1), points(:,2), '.-');
grid on
xlim([100 150])
ylim([580 650])
It looks like there are 4 "bad" data points. Why do you think that you need to invent new positions for those 4 points?
I would just ignore them. Extrapolation is almost always a bad idea.
figure
idx = 5:size(points,1);
plot(points(idx,1), points(idx,2), '.-');
grid on
0 Commenti
TENG LIU
il 8 Nov 2023
I found that the first 4 are not aligned, you can consider just exclude the first 4 and interpolated them by using 5th and 6th, code is here:
x= points(5:6,1);
v = points(5:6,2);
xq = points(5,1):0.25:points(6,1);
vq1 = interp1(x,v,xq);
Then the new points display as:
points(1:6,1) = xq;
points(1:6,2) = vq1;
If you want to plot them, just:
figure,scatter(points(:,1),points(:,2))
0 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!