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
256789;267825;625892;982895;598289

Model the three degree of freedom system shown in Figure Q5 and solve for the displacements of the three masses due to a force of 10 N applied to the bottom mass at a frequency of

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

Command Window: To the left of the Command Window, there are 2 tabs for the Current Directory Window and Workspace Window. If the Current Directory tab is selected, the files

I have a file to be read in matlab which carries different columns in it. Each column has around 200000 readings in set of 2000. I want a code in a loop which gives stores each col

Documentation: It is very important that all the scripts be documented well, so that the people can understand what the script does and how it accomplishes that. One way of do

For the 66kV subtransmission network shown below, calculate the following, using a MATLAB Simulink Power System Blockset model: 1. Three phase, phase-to-phase and phase-to-earth

Problem of a projectile being launched at an angle of O at an initial velocity ofv. The equations for the height hand horizontallocation x as functions of time t are as follo


Relational Expressions: The Conditions in if statements use expressions which are theoretically, or logically, either true or false. These expressions are termed as relational