how do i use the if statement in a for loop

1 view (last 30 days)
How do i use the IF statement to achieve my objective. I want the values of n for certain conditions to be output iteratively into a matrix and plotted (Julia sets)
c=-0.835 - 1i*0.232;
x=-2:0.005:2;
y=-2:0.005:2;
[X,Y]=meshgrid(x,y);
z=(X + Y*1i);
n_max=256;
b=10000; %blowup parameter. stop an iteration when |z|>b.
a=(abs(z)>=10000);
m=(z.^n_max<10000)
n_matrix = zeros(800,800);
for n = 1:n_max
f_z = z.^n + c;
z = f_z ;
if a disp(n)
if m disp (n)
end
end
end
colormap prism(256)
pcolor(n);
shading flat;
axis('square','equal','off')

Accepted Answer

Matt J
Matt J on 6 Oct 2012
Edited: Matt J on 6 Oct 2012
This is literally what you asked for, but maybe not what you wanted.
ntable=1:nmax;
for n=1:nmax
if condition_does_not_hold
ntable(n)=nan;
end
end
plot(ntable);
  2 Comments
Ejike
Ejike on 6 Oct 2012
thanks. i will just like clarification on (nan) and if condition holds.
Ejike
Ejike on 6 Oct 2012
i actually need
if condition_holds ntable(n)= (n_for_ that_condition)
end

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!