필터 지우기
필터 지우기

How to extrapolate the first 5 points

조회 수: 3 (최근 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.

답변 (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 CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by