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

Iterative root fi nding method, The secant method is an iterative root ndi...

The secant method is an iterative root nding method that is super-linear. The method has the advantage that it is faster than linear methods and does not require knowledge of the

Functions, Need help with creating functions in matlab.

Need help with creating functions in matlab.

Rc phase shift oscillater, design a rc phase shift oscillator for a particu...

design a rc phase shift oscillator for a particular frequency of oscillation and generate a sinusoidal signal

Need help with assignment, Hi I''m wondering if someone can help me with Ma...

Hi I''m wondering if someone can help me with Matlab coursework

Relational expressions, Relational Expressions: The Conditions in if s...

Relational Expressions: The Conditions in if statements use expressions which are theoretically, or logically, either true or false. These expressions are termed as relational

Linear Programming, Ft. Loudoun and Watts Bar are two large hydroelectric d...

Ft. Loudoun and Watts Bar are two large hydroelectric dams, the former upstream of the latter. The level of Watts Bar Lake must be kept within limits for recreational purposes, and

Michael, Write a Matlab function that computes y1= tan(x) and y2= sin(x)/co...

Write a Matlab function that computes y1= tan(x) and y2= sin(x)/cos(x), returns the difference |y1–y2| and prints a message whether the two are equal or not. Test your function for

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