I'm starting in Matlab and I have to code centred loops spreading in different directions. Just like the picture I added. Any guidance on where to start would be appreciated.

1 回表示 (過去 30 日間)
Tammy
Tammy 2021 年 12 月 16 日
回答済み: Mathieu NOE 2021 年 12 月 16 日
I'm starting in Matlab and I have to code what I think it is centred loops spreading in different directions. Just like the picture I added. This represents a desert ant lookig for its home and each loop adds uncertainty. Any guidance on where to start would be appreciated.

回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 12 月 16 日
hello
try this
circles_radius = 1;
radius_noise_amplitude = 0.05;
center_radius = 2;
center_radius_noise_amplitude = 0.25;
nb_of_circles = 25;
figure(1);
axis square
hold on
for ci = 1:nb_of_circles
center(1) = center_radius.*cos((ci-1)*2*pi/nb_of_circles)+center_radius_noise_amplitude*randn;
center(2) = center_radius.*sin((ci-1)*2*pi/nb_of_circles)+center_radius_noise_amplitude*rand;
[XData,YData] = circle(center,circles_radius,radius_noise_amplitude);
plot(XData,YData);
end
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [XData,YData] = circle(center,radius,radius_noise_amplitude)
points = 100;
theta = 0:2*pi/(points-1):2*pi;
XData = center(1)+radius.*cos(theta)+radius_noise_amplitude*randn(size(theta));
YData = center(2)+radius.*sin(theta)+radius_noise_amplitude*randn(size(theta));
end

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by