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
Scripts to Produce and Customize the Simple Plots: The MATLAB has many graphing capabilities. In most cases, customizing plots are desired and this is the simplest to accompli

Read in any non jpeg image (any image will do) . Save it as a jpeg at quality levels (70, 60,50,40, 30) Get the MSE for each quality level as compared to the orignal file Get the

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


I want codding in matlab for vogel approximation method . i mean .M file for vogels approximation method.

Creating Column Vectors: One way to generate a column vector is by explicitly putting the values in square brackets, separated by the semicolons: >> c = [1; 2; 3; 4] c =

Common form of a function definition: The common form of a function definition for a function which computes and returns one value looks like this: For illustration, t

plase help me to convert a theory part of ammonia-vapour simple absorption system into matlab programmong

1) Convert the table into format convenient for the processing with MATLAB. 2) Prepare a program that perform K Nearest Neighbours algorithm using Euclidian distance. (Your prog

An FIR filter has coefficients b = [ 1.0000   -0.6387    1.0214    0.8210   -0.7470    1.0920 ] (a) Find H(z) for the filter and plot its frequency response (magnitude and phase