How to extrapolate the first 5 points

2 ビュー (過去 30 日間)
DB
DB 2023 年 11 月 8 日
編集済み: Torsten 2023 年 11 月 8 日
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.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 8 日
Why not just ignore the points?

サインインしてコメントする。

回答 (4 件)

Torsten
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)

John D'Errico
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.

Les Beckham
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

TENG LIU
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))

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by