Illustration of switch statement, MATLAB Programming

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

Posted Date: 10/19/2012 3:25:28 AM | Location : United States







Related Discussions:- Illustration of switch statement, Assignment Help, Ask Question on Illustration of switch statement, Get Answer, Expert's Help, Illustration of switch statement Discussions

Write discussion on Illustration of switch statement
Your posts are moderated
Related Questions
how to control a suspension by linear quadratic regulator method?

Calling a Function: Here is an illustration of the call to this function in which value returned is stored in the default variable ans: >> calcarea(4) ans = 50.2655

i want to write a program in mat lab for optimizing the design of lens help me how could i i am new user of matlab but previously i have work on C++.

2)''dbcont'' command for debugging is used to Select one: a. Continue normal code execution from the debug prompt. b. List all breakpoints. c. Execute (step) one or more lines

ACTIVITIES OF A PROJECT 1-2 1-3 1-4 1-5 2-6 3-6 3-7 4-7 5-7 7-6 6-8 7-8 THE COMMPANY LOSES 2,000 FOR EVERY WEEK THE PROJECT LASTS BEYOND 30 WEEKS. fOR EACH OF THE PROPOSALS; ACTIVI

http://messenger.providesupport.com/messenger/ae.html?ps_s=U4nFMQo4BP04

Function Functions: The one reason for using function handles is to be able to pass functions to the other functions-these are known as function functions. For illustration

1. Write a function to threshold your images separating the background from the foreground: Implement the "peakiness" detection algorithm described in class. The output of your

1) Identify an equation that describes some chemical process.  Your equation should have at least two parameters, at least one of which should contribute in a non-linear way. He

Read in any non jpeg image (any image will do) . Save it as a jpeg at quality levels (70, 60,50,40, 30) Get the MSE for each quality level as compared to the orignal file Get the