Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
use of 'if' statement

Subject: use of 'if' statement

From: Ejike

Date: 6 Oct, 2012 16:30:08

Message: 1 of 3

how do i use the if statement to tell my program to put the value of n in a matrix given the conditions stated:

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=abs(z)>=10000; %blowup parameter. stop an iteration when |z|>b.
a=abs(z);
m=z.n_max<10000
n_matrix = zeros(800,800);
for n = 1:n_max
    f_z = z.^n + c;
    z = f_z ;
   if b disp(n)
     if m disp
    n_matrix(b&m) = n;
end
   end
end
colormap prism(256)
pcolor(n);
shading flat;
axis('square','equal','off')

Subject: use of 'if' statement

From: dpb

Date: 6 Oct, 2012 17:53:09

Message: 2 of 3

On 10/6/2012 11:30 AM, Ejike wrote:
> how do i use the if statement to tell my program to put the value of n
> in a matrix given the conditions stated:
...

> b=abs(z)>=10000; %blowup parameter. stop an iteration when |z|>b.

b is a logical array the size(z)

If the idea is to stop when any location exceeds the limit then

if any(b)

doc if

discusses how Matlab evaluates the if condition...

--

Subject: use of 'if' statement

From: Ryan

Date: 8 Oct, 2012 20:30:19

Message: 3 of 3

Pretty straightforward:
http://www.mathworks.com/help/matlab/ref/if.html

Desktop > Editor > Set a Breakpoint and Run. Hit F11 multiple times to step through the code and test the logic.

Ryan---

"Ejike " <askmewai3@gmail.com> wrote in message <k4pmag$r3a$1@newscl01ah.mathworks.com>...
> how do i use the if statement to tell my program to put the value of n in a matrix given the conditions stated:
>
> 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=abs(z)>=10000; %blowup parameter. stop an iteration when |z|>b.
> a=abs(z);
> m=z.n_max<10000
> n_matrix = zeros(800,800);
> for n = 1:n_max
> f_z = z.^n + c;
> z = f_z ;
> if b disp(n)
> if m disp
> n_matrix(b&m) = n;
> end
> end
> end
> colormap prism(256)
> pcolor(n);
> shading flat;
> axis('square','equal','off')

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us