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
Compute the result: To compute the area, the formula is required. In this situation, the area of the circle is π multiplied by the radius squared. Therefore, that means the va

Calculating and Visualizing Sequence Statistics Follow the instructions in this demo file to download a sequence and calculate and visualize its statistics. Save all the command

how to make a histogram of data, example x=[5 6 3 2 5] and then find the distribution

How to Open Simpower: 1. Open MATLAB 2. In the "Command Window" write ' simulink ' and press Enter or click on the Simulink icon. 3. Simulink Library Browser w

Functions with Local Variables: The functions we have seen faraway have been very easy. Though, in many situations the computations in a function are more complex, and may nee


write a computer program that will provide a user with the equilibrium concentration of vacancies in a metallic element as a function of temperature.Temperature range should be men

MRI (magnetic resonance imaging) scanners allow doctors to now obtain complete body images for medical diagnosis purposes. The system produces scans which represent slices through

The average speed of vehicles on a freeway is being studied. Assume that the standard deviation of vehicle speed is known to be 8 km/h. (a) Suppose observations on 120 vehicles