Distribute data in the form of a circle

11 ビュー (過去 30 日間)
Nasir Mehmood
Nasir Mehmood 2021 年 3 月 31 日
編集済み: John D'Errico 2021 年 4 月 1 日
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.
Thanks in advance.
Nasir
  2 件のコメント
KSSV
KSSV 2021 年 3 月 31 日
What have you attempted for your work?
Nasir Mehmood
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;
rad = 100;
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
John D'Errico 2021 年 4 月 1 日
編集済み: 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;
radDecay = @(r,rate) pi*exp(-r*rate);
fplot(@(r) radDecay(r,rate1),[0,200])
hold on
fplot(@(r) radDecay(r,rate2),[0,200])
fplot(@(r) radDecay(r,rate3),[0,200])
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 件のコメント
Nasir Mehmood
Nasir Mehmood 2021 年 4 月 1 日
編集済み: Nasir Mehmood 2021 年 4 月 1 日
Thanks for a detailed response dear John!
Yes, it is infact an exponential decay which is required. However, i need a more control on the data distribution in such a way that i may increase or decrease the central (& outer) region so that the transition region (where the value is changing from inner region to outer region) can be varied. It means, there should be some area inside and outside which have constant values of data.
John D'Errico
John D'Errico 2021 年 4 月 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);
fplot(@(r) radDecay(r,0.025),[0,200])
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.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral PDEs についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by