# Distribute data in the form of a circle

28 ビュー (過去 30 日間)
Nasir Mehmood 2021 年 3 月 31 日

Hello!
How to create a 2D grid of data in following two cases?
Case 1: Input data (say "z1") is in such a way that z1 = pi at the center and it decays to z1 = 0 outwards (like a circle on the 2D grid).
Case 2: Input data (say "z2") with formula z2 = atan[(y-y0)/(x-x0)] + pi/2, in which (x0,y0) being the center of the square grid.
Note: The output 2D grid has to be used for further calculations.
Nasir
##### 2 件のコメント表示非表示 1 件の古いコメント
Nasir Mehmood 2021 年 4 月 1 日
For case1: I've attempted the idea of "creating circle" combined with "Euclidean distance transform". The code is as under:
mesh_x = 401;
mesh_y = 401;
[xx, yy] = meshgrid(1:mesh_x, 1:mesh_y);
x_0 = 200;
y_0 = 200;
circ_log = (yy - y_0).^2 + (xx - x_0).^2 <= rad.^2;
edt_log = bwdist(~circ_log);
edt_norm = edt_log / max(edt_log(:));
theta = edt_norm*pi;
contourf(xx, yy, theta, 100, 'LineColor', 'none')
colorbar;
it results in the following image: However, this does not completely satisfy my requirement. Because i need a thinner transition region and somehow wider inner region.
For case 2: This issue is almost solved by creating an "array of zeros" and filling it with "for loop" according to the given formula.

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

### 採用された回答

John D'Errico 2021 年 4 月 1 日

You say you want to distribute data, which implies you want to see random numbers, based on some vague, unspecified distribution. But really, it looks as if you just want to create several 2-dimensional surfaces?
In the first case, you talk about some function being pi at the center of your grid, and then it needs to "decay". But we don't know what shape the decay should follow. I suppose an exponential decay would be acceptable, but even then, we are not told how fast that should be! Consider these three profiles:
rate1 = 0.2;
rate2 = 0.025;
rate3 = 0.01;
hold on
legend('Fast decay','Slow decay','Really slow decay')
hold off So they all start at pi at the center, and decay with different rates. Implement that as a surface simply enough. I'll use the intermediate decay rate here. As you can see, at a distance of 200 units from the center, the intermediate decay rate will be almost zero, though it will never truly get to exactly zero. That is what exponential decay means.
[X,Y] = meshgrid(-200:200);
[~,S1] = cart2pol(X,Y); S1 = radDecay(S1,rate2);
figure
H = surf(S1);
H.LineStyle = 'none'; So that shows the basic shape I've created. You can feel free to fine tune the rate to make it look as you wish. Larger values for the rate parameter will create a surface that decays more rapidly.
figure
H = pcolor(S1);
H.LineStyle = 'none'; Some other fundamental shape would be as easy to implement. That is your choice. The idea is to create the shape you want for the radial decay first. THEN implement it as a surface as I did. meshgrid and cart2pol will do all the work for you.
##### 2 件のコメント表示非表示 1 件の古いコメント
John D'Errico 2021 年 4 月 1 日
I fail to see the problem. Just pick some distance where that function becomes truly zero. WTP? So you might do it as:
zerobreak = 100;
radDecay = @(r,rate) pi*exp(-r*rate) .* (r<zerobreak); I've chosen a limit where the truncation is painfully obvious. But you can choose any set of constants you wish. And if you want it to be some other non-zero constant, it is also trivially easy.
Since your surfaces are always circularly symmetric, just design the shape in the radial direction you want as a 1-dimensional profile FIRST. This allows you to envision exactly the profile you want to see happen.

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

R2016a

### Community Treasure Hunt

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

Start Hunting!