Generate (X,Y) grid coordinates from within contour boundary

2 ビュー (過去 30 日間)
mackhina
mackhina 2020 年 1 月 10 日
編集済み: mackhina 2020 年 1 月 10 日
Hi Everyone
I have the (X,Y,Z) coodinates for a contourf plot.
I want to extract sample (X2,Y2) coordinates for a given size within the contour area under the input Z value threshold.
E.g. I only want Z values for Z_threshold = 10. If I input grid_size = 5, I want to get (X2,Y2) points spaced at 5m x 5m within the threshold contourf(X,Y,Z) area.
I can create the right size grid by using linspace, but I don't know how to restrict these coordinates to be only from within the desired contour area though?
load('contour_data.mat','X','Y','Z');
Z_threshold = 10;
grid_size = 20;
Z(Z > Z_threshold )= NaN;
contourf(X,Y,Z);
hold on
x_grid = linspace(min(X(:)), max(X(:)), range(X(:))/grid_size);
y_grid = linspace(min(Y(:)), max(Y(:)), range(Y(:))/grid_size);
[X2,Y2] = meshgrid(x_grid,y_grid);
plot(X2,Y2,'.r');
hold off
I only want (X2,Y2) from within the green circled zone below. Note that (X2,Y2) don't correspond to (X,Y) points.
contourf_grid.png
Thanks for any advice :)

採用された回答

KSSV
KSSV 2020 年 1 月 10 日
  1. Use boundary to get the boundary of your required region.
  2. Use inpolygon with the generated grid and boundary points to get the points lying inside the area of interest.
  3. Useing the indices generated from inpolygon, you can get your required points.
  1 件のコメント
mackhina
mackhina 2020 年 1 月 10 日
編集済み: mackhina 2020 年 1 月 10 日
Loads slow for my 8 million point plot, but the results are just what I needed. Thanks for the advise!
I found this guide very helpful to do what I wanted for anyone else trying to do the same thing:

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by