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
Related Structure Functions: There are many functions which can be used with structures in a MATLAB. The function isstruct will return 1 for logical true when the variable arg

Anonymous Functions: The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This ca

Illustration of initializing the data structure: illustration of initializing the data structure by preallocating is here as shown: >> cyls(3) = struct('code', 'c', 'dimen

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Technique to creating this structure: An alternative technique of creating this structure, that is not as efficient, includes using the dot operator to refer to fields in the

Set Operations: The MATLAB has numerous built-in functions which perform set operations on vectors. These involve intersect, union, setdiff, unique, and setxor. All these func

deblank function: The deblank function eliminates only trailing blanks from the string, not leading the blanks. The strtrim function will eliminate both the leading and traili

Reduced Row Echelon Form: The Gauss Jordan technique results in a diagonal form; for illustration, for a 3 × 3 system: The Reduced Row Echelon Forms take this one step

Structures: The Structures are data structures which group together values which are logically related in what are known as the fields of structure. The benefit of structures