Extract data below a curve

1 Ansicht (letzte 30 Tage)
TAPAS
TAPAS am 27 Jan. 2021
Bearbeitet: Veronica Taurino am 12 Mär. 2021

I have a gridded data as given in the figure. I want to extract data below the given line(ABCDEFGHI). The co-ordinate of the corner point of the line is given. That means I want to keep only data below that line.

Antworten (1)

Veronica Taurino
Veronica Taurino am 12 Mär. 2021
Bearbeitet: Veronica Taurino am 12 Mär. 2021
Your input data is something like that:
% Hypotesis: black points do not overlay the grid (can lay in between blue points)
A =[1 4.5];
B = [2.5 5.3];
C = [3.5 5.1];
D = [6.2 6.1];
E = [6.8 6.1];
F = [7.2 6];
G = [9.5 4.8];
H = [11.2 5.5];
I = [13 5];
ALL= [A;B;C;D;E;F;G;H;I];
plot(ALL(:,1),ALL(:,2))
[X,Y] = meshgrid(1:12,1:7); %gridded point
hold on
plot(X,Y,'.k') % grid
If your black points (A,B,C,...) do not overlay the grid but can lay in between blue points, like this:
first you need to evaluate the red point I dotted in red in the image above with a linear interpolation:
xq = [1 2 3 4 5 6 7 8 9 10 11 12]; % X-grid coordinates at which evaluate the Y
vq = interpn(ALL(:,1)',ALL(:,2)',xq,'linear');
and then you can do a comparison like that:
for jj=1:size(Y,2)
YY(:,jj)=Y(:,jj)<=vq(jj)
end
% Plot only remaining points
plot(X(YY),Y(YY),'or')
  1 Kommentar
Adam Danz
Adam Danz am 12 Mär. 2021
+1, nice approach
1 error and 1 inefficiency to improve,
  1. D and E are the same coordinate in the current version of your answer and that causes an error in interpn due to duplicity.
  2. The jj-loop can be replaced by,
YY = Y < vq;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by