If-else statement, MATLAB Programming

The IF-ELSE Statement:

The if statement selects whether an action is executed or not. Selecting between the two actions, or selecting from numerous actions, is accomplished by using if-else, nested if, and switch statements.

The if-else statement is used to select between the two statements, or sets of statements. The common form is as shown below:

if condition

action1

else

action2

end

 

At First, the condition is computed. If it is theoretically true, then the set of statements elected as action1 is executed, and that is it for the if-else statement. If rather the condition is theoretically false, the second set of statements elected as action2 is executed, and that is it. The first set of statements is known as the action of the if clause; it is what will be executed if the expression are true. The second set of statements is known as the action of the else clause; it is what will be executed if the expression is false. One of these actions, and only one, will be executed-that one depends on the value of the condition.

For illustration, to establish and print whether or not a random number in the range from 0 to 1 is less than 0.5, an if-else statement can be used:

if rand < 0.5

disp('It was less than .5!')

else

disp('It was not less than .5!')

end

Posted Date: 10/19/2012 3:18:31 AM | Location : United States







Related Discussions:- If-else statement, Assignment Help, Ask Question on If-else statement, Get Answer, Expert's Help, If-else statement Discussions

Write discussion on If-else statement
Your posts are moderated
Related Questions
Variable number of output arguments: The variable number of output arguments can also be identified. For illustration, the one input argument is passed to the below function t


Variable names: Variable names are an example of the identifier names. The rules for identifier names are as shown below: (A)The name should begin with a letter of the alph

Generates sin or cos wave using plot functions: The script generates an x vector; iterating through all the values from 0 to 2*π in steps of 2*π /40 gives sufficient points to

how to convert char array to a string cell


#question.i want to know the number of pixels related to the actual phase value and want to separate the zero phase valued pixels from the image..

Consider the 3rd order Bessel function J3(x). Write a script findBessRoots.m that computes all the roots of J3(x) in the interval [0; 40]. Your script must store the roots of the f

Error in variables statements: Error: The expression in the left of equals sign is not a valid target for an assignment. >>  By placing a semicolon at the end of the sta

Damped free vibrations can be modelled by considering a block of mass m that is attached to a spring and a dashpot as shown. From Newton's second law of motion, the displac