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

Illustration of script, Illustration of script: For illustration, we w...

Illustration of script: For illustration, we will now generate a script known as script1.m which calculates area of the circle. It assigns a value for the radius, and then com

Function program, write a function program to compute a standard deviation ...

write a function program to compute a standard deviation of a number

Determine the ball temperature , In the manufacturing of ball bearings, the...

In the manufacturing of ball bearings, the components, such as the ball, are hardened through a process of heating and then rapid cooling or "quenching" by submersion in an oil or

Advection-diffusion, You are to submit your completed MATLAB code and a sho...

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

Generate a script, Generate a script: To generate a script, click File...

Generate a script: To generate a script, click File, then New, and then M-file. The new window will appear known as the Editor. To generate a new script, simply type the serie

Matlab programming vector algebra, Matlab Programming Vector Algebra : Crea...

Matlab Programming Vector Algebra : Create a program package for calculation of distances and intersections of lines and planes. Plot the results in a graphical representation

Find the dft frequency resolution, (a) Using Matlab, find and plot the magn...

(a) Using Matlab, find and plot the magnitude of the DTFT of 10 samples of x(n) for n=[0:1:9] of x(n) = cos(2*pi*f1*n) + cos(2*pi*f2*n)  for f1=0.22 and f2=0.24 and pad zeros to ge

Excel, Ask question Excel Ch 1.A-Grader Project-Training Workshops 1.5#Mini...

Ask question Excel Ch 1.A-Grader Project-Training Workshops 1.5#Minimum 100 words accepted#

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