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
Illustration of Gauss elimination: For illustration, for a 2 × 2 system, an augmented matrix be: Then, the EROs is applied to obtain the augmented matrix into an upper

Splits a string : The strtok function splits a string into pieces; it can be called in many ways. The function receives one string as an input argument. It appears for the fir

function imread: The function imread can read an image file, for illustration a JPEG (.jpg) file. The function reads color images into a 3-dimensional matrix. >> myimage1

Function rmfield - structure: The function rmfield eliminates a field from the structure. It returns a new structure with field eliminated, but does not modify the original st

Illustration of Matrix solutions: For illustration, consider the three equations below with 3unknowns x 1 ,x 2 , and x 3 : We can write this in the form Ax = b here A

Indexing into Vectors of structures: Frequently, when the data structure is a vector of structures, it is essential to iterate through the vector in order by various fields. F

Illustration of Graphics properties: A particular property can also be exhibited, for illustration, to view the line width:     >> get(hl,'LineWidth')     ans =

Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str

Finding a sting - function findstr: The function findstr receives two strings as input arguments. It finds all the occurrences of shorter string contained by the longer, and r

Individual structure variable: The individual structure variable for one software package may look like this: The name of the structure variable is a package; it has f