Creating a fractal using for and if structures
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi! I'm relatively new at using MATLAB. I'm trying to create a fractal from a given algorithm and this is the code I made. When I run the code I only get an empty plot. Any ideas as to what I'm doing wrong? (I'm sure a lot haha!) I appreicate your help.
m = 2;
n = 1;
hold on
for ii = 1:1000
q = 3*rand(1);
if q < 1
m = m/2;
n = n/2;
end
if q < 2
m = m/2;
n = (300+n)/2;
end
if i <1000
plot (m,n)
end
hold off
end
Respuestas (2)
Nishant Gupta
el 12 de Sept. de 2019
Hi Emani,
As Walter said you can use this line:
plot (m,n,'*');
to get the point on the plot and if you want all the points you can delete 'hold off' from your code. Then the plot will be as follows:
0 comentarios
Mohammad Hadi Namdar
el 2 de Jun. de 2021
function func_q26(m,n)
figure(1)
hold on
for i = 1:100000
q = 3*rand(1);
if q < 1
m = m/2;
n = n/2;
if i < 1000
plot(m,n,'.k')
else
break
end
elseif q < 2
m = m/2;
n = (n+300)/2;
if i < 1000
plot(m,n,'.k')
else
break
end
else
m = (m+300)/2;
n = (n+300)/2;
if i < 1000
plot(m,n,'.k')
else
break
end
end
end
hold off
0 comentarios
Ver también
Categorías
Más información sobre Fractals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!