Illustration of if - else statement, MATLAB in Engineering

Illustration of if - else statement:

The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted the user for a radius, and then used that to compute the area of a circle. Though, it did not check to make sure that the radius be valid (example, a positive number). Here is a modified script which checks the radius:

1653_Illustrations of if statement1.png

Illustrations of running this script whenever the user enters invalid and then valid radii are shown here:

>> checkradius

Please enter the radius: -4

Sorry; -4.00 is not a valid radius

>> checkradius

Please enter the radius: 5.5

For a circle with radius of 5.50, the area becomes 95.03

The if-else statement in this illustration selects between two actions: printing an error message, or really using the radius to compute the area, and then printing out the result. Note that the action of the if clause is a single statement, while the action of the else clause is a group of three statements.

Posted Date: 10/19/2012 3:20:00 AM | Location : United States







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

Write discussion on Illustration of if - else statement
Your posts are moderated
Related Questions
Forward elimination: In forward elimination, we want to obtain a 0 in the a 21 position. To accomplish this, we can alter the second line in the matrix by subtracting from it

Matrix definitions: As we know the matrix can be thought of as a table of values in which there are both rows and columns. The most common form of a matrix A (that is sometime

A matlab function to calculate filter order

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func

Matrix operations: There are some common operations on matrices. The operators which are applied term by term, implying that the matrices should be of similar size, sometimes

Image Processing: The Images are represented as grids, or matrices, of picture elements (known as pixels). In MATLAB an image usually is represented as a matrix in which each

printrectarea function: function call: printrectarea(length, width) function header: function printrectarea(len, wid)   In the function call, there are two argume

Defined a variable in work space: The variables defined in the script will become a part of the workspace: >> clear >> who >> mysummfile    15 >> who

Execution steps: Whenever the program is executed, the steps below will take place: The script calcandprintarea starts executing. The calcandprintarea calls the readr

Example of file ploting data: As the other example, a data file called 'compsales.dat' stores the sales figures (in millions) for divisions in a company. Each line in the f