# Extract data below a curve

2 ビュー (過去 30 日間)
TAPAS 2021 年 1 月 27 日

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. サインインしてコメントする。

### 回答 (1 件)

Veronica Taurino 2021 年 3 月 12 日

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 件のコメント表示 なし非表示 なし
Adam Danz 2021 年 3 月 12 日
+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;

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

### カテゴリ

Find more on Interpolation in Help Center and File Exchange

R2017b

### Community Treasure Hunt

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

Start Hunting!