Illustration of switch statement, MATLAB Programming

Assignment Help:

Illustration of switch statement:

Here are the two illustrations of calling this function:

>> quiz = 22;

>> lg = switchletgrade(quiz)

lg =

X

>> quiz = 9;

>> switchletgrade(quiz)

ans =

A

Note that it is supposed that the user will enter an integer value. When the user does not, either an error message will be printed or a wrong result will be returned. As the similar action of printing 'A' is desired for more than one situation, these can be combined as shown below:

switch quiz

    case {10,9}

      grade = 'A';

    case 8

      grade = 'B';

     % etc.

(The curly braces around the case expressions 10 & 9 are essential.)

In this illustration, we checked the error first using an if-else statement, and then if the grade was in the valid range, used the switch statement to find the corresponding letter grade.

At times the otherwise clause is used rather than for the error message. For illustration, if the user is assumed to enter only a 1, 3, or 5, the script may be organized as shown below:

2081_Illustration of switch statement.png

In this situation, actions are taken if the user properly enters one of the valid options. When the user does not, the otherwise clause handles, by printing an error message.

Note that the use of two single quotes within the string to print one.

>> switcherror

Enter a 1, 3, or 5: 4


Related Discussions:- Illustration of switch statement

Tuning Fractional PID using GA and PSO algorithm, my project is on load fre...

my project is on load frequency control using FPID tuned using GA and PSO algorithm.the system is a two area system.

Example of variables and assignment statements, Example of Variables and as...

Example of Variables and assignment statements: The expression is computed and then that value is stored in the variable. For illustration, this is the way it would appear in

Speech recognition using support vector machine, what are data collect th...

what are data collect this topic,how i can create algorithm in mat lab what language support easy to this topic

Variable numbers of arguments, Variable numbers of arguments: In the f...

Variable numbers of arguments: In the functions there have been a fixed number of input and output arguments. For illustration, in the function below, there is one input argum

Show the output - algorithms, Show the output - algorithms: Where does...

Show the output - algorithms: Where does the output go? The two possibilities are (i) to an external file, or (ii) to a window on the screen. Based on system, one of these wil

Visual cryptography, how to implement 3 out of 4 visual cryptography in MAT...

how to implement 3 out of 4 visual cryptography in MATLAB?

variable names, Variable names: Variable names are an example of the ...

Variable names: Variable names are an example of the identifier names. The rules for identifier names are as shown below: (A)The name should begin with a letter of the alph

Matrix addition, Write a program in Mathlab for addition of two matrices.

Write a program in Mathlab for addition of two matrices.

Define a function, Define a function: The radius of a circle is passed...

Define a function: The radius of a circle is passed to the function to input argument  rad; the function computes the area of this circle and stores it in the output argument

Colon operator, The Colon Operator: If the values in the vector are re...

The Colon Operator: If the values in the vector are regularly spaced, the colon operator is used to iterate through these values. For illustration, 1:5 results in all the inte

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd