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 view (last 30 days)
Tammy
Tammy on 16 Dec 2021
Answered: Mathieu NOE on 16 Dec 2021
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.

Answers (1)

Mathieu NOE
Mathieu NOE on 16 Dec 2021
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

Community Treasure Hunt

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

Start Hunting!

Translated by