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!