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
Write a MATLAB program that calculates the arithmetic mean, and the root-mean-square average for a given set of values. The output should be formatted as follows: Y

Write a matlab function that calls eig and generates an estimate of the smallest three eigenvalues and associated eigenfunctions of the negative Laplacian operator on ?. (Hint: thi

You are to submit your completed MATLAB code and a short written report through the Blackboard upload facility as a single zip ?le. This zip ?le should consist of your ?nite volume

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

Q. Explain Power system toolbox ? Power system toolbox (PST) was developed to enable users to perform power system analysis within MATLAB. PST may be used on any computer syste

Constants: The variables are used to store values which can change, or that are not known ahead of the time. Most of languages also have the capacity to store constants that a

Illustration of Variable number of input arguments: In this situation, it was supposed that the radius will always be passed to the function. The function header can hence be

i want matlab code for DFB Equiliser and the output between tha number of iterations vs MSE

Make a vector of 500 random numbers from a normal distribution with mean 2 and standard deviation 5(randn). a After you generate the vector, verify that the sample mean and stan

Goal: Learn how to do statistics, sorting and curve fitting in Matlab. Put all of those ".m" files in a folder called yourname_lab7, and zip the folder and submit it on the class w