How to extrapolate the first 5 points
2 次查看(过去 30 天)
显示 更早的评论
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.
回答(4 个)
Torsten
2023-11-8
编辑:Torsten
2023-11-8
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 个评论
John D'Errico
2023-11-8
编辑:John D'Errico
2023-11-8
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 个评论
Les Beckham
2023-11-8
编辑:Les Beckham
2023-11-8
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 个评论
TENG LIU
2023-11-8
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!