I want to extract a circle of values from a meshgrid

5 ビュー (過去 30 日間)
Justin Dubin
Justin Dubin 2018 年 5 月 22 日
回答済み: Image Analyst 2018 年 5 月 23 日
I have a 2D meshgrid with dimensions of distance x distance. I want to know the values at a fixed radius from the center.

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
編集済み: Ameer Hamza 2018 年 5 月 22 日
What do you need value from mesh grid, you can calculate the points on the perimeter of the circles using pol2cart(). For example
r = 1
[x,y] = pol2cart(linspace(0, 2*pi, 100), r)
will give you x, y coordinates of points in the circle of radius r.
Edit: If you want to find the points from the mesh grid, then the following code can help
x = -5:1:5;
y = -5:1:5;
[X Y] = meshgrid(x,y);
r = 3; % radius
tolerane = 2;
indicator = abs(X.^2 + Y.^2 - r^2) < tolerane;
xCircle = X(indicator);
yCircle = Y(indicator);
Since points on the grid are discrete you will need to define a tolerance to for accepting a point. You will need to tune the tolerance parameter according to the resolution of your grid to get all points on the circle.
  4 件のコメント
Justin Dubin
Justin Dubin 2018 年 5 月 23 日
Yes, this does the job just fine. Thank you, Ameer!
Ameer Hamza
Ameer Hamza 2018 年 5 月 23 日
You are welcome.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 5 月 23 日

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by