Creating a fractal using for and if structures
17 ビュー (過去 30 日間)
古いコメントを表示
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
回答 (2 件)
Nishant Gupta
2019 年 9 月 12 日
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 件のコメント
Mohammad Hadi Namdar
2021 年 6 月 2 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!