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
Creating Cell arrays: There are many ways to create cell arrays. For illustration, we will create a cell array in which one element will store an integer, one element store ch

Replacing, Finding, and separating strings: There are numerous functions which find and replace the strings, or parts of strings, within the other strings and functions which

Subfunctions: Though, it is possible to have more than one function in a given M-file. For illustration, if one function calls the other, the first function would be the prima

readlenwid function: function call: [length, width] = readlenwid; function header: function [l,w] = readlenwid In the function call, not any argument is passed; henc

I have a vector of X, one for Y , one for x-direction velocity U and one for y-direction velocity V. they are at same size. How can I plot streamline of that flow? I follow all exa

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

Variable Scope: The scope of any of variable is the workspace in which it is valid. The workspace generated in the Command Window is known as the base workspace. As we know

Text graphic function - Graphics objects: The text graphic function permits text to be printed in a Figure Window, involving special characters which are printed by using \spe

Matrix solutions to systems of the linear algebraic equations: The linear algebraic equation is an equation of the form a 1 x 1 + a 2 x 2 + a 3 x 3    .  .  .  .  a n x n

Illustration of Image processing: This displays that there are 64 rows, or in another word, 64 colors, in this specific colormap. It also displays that the first five colors a