Extract data below a curve
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Veronica Taurino
on 12 Mar 2021
Edited: Veronica Taurino
on 12 Mar 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 Comment
Adam Danz
on 12 Mar 2021
+1, nice approach
1 error and 1 inefficiency to improve,
- D and E are the same coordinate in the current version of your answer and that causes an error in interpn due to duplicity.
- The jj-loop can be replaced by,
YY = Y < vq;
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!