Wednesday, November 10, 2010

MATLAB-2

in this article i want to discuss about how to write for loop and if statement.
the following code gives an idea about for loop...............and this code generates the numbers from 1 to 10.
for i=1:10
disp(i);
end
so from the code we can say every for loop should have an end statement.............that end statement is end.
the if statement uses some logical operators for decision making........they r
&-and
|-or
~-negation
observe the following code for if statement..........

a=input('enter the value of a');
b=input('enter the value of b');

if((a>1)&(b>1))
for i=1:10
disp(i);
end
end

the code gives the output as the number from 1 to 10 if and only if a>1 and b>1.thats it

No comments:

Post a Comment