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

Vectors and matrices, Vectors and Matrices: The Vectors and matrices a...

Vectors and Matrices: The Vectors and matrices are used to store sets of values, all of which are similar type. A vector can either be a column vector or a row vector. The mat

Homework, -The program should run always until the user enters -1 to exit f...

-The program should run always until the user enters -1 to exit from the program. - In the main, you should ask user to input any angles in degrees (Ad) and an integer number (N).

Crank-nicolson method, clear tic L=1; T=0.2; nust=2000; dt=T...

clear tic L=1; T=0.2; nust=2000; dt=T/nust; n=40; dx=L/n;   r=1;  omega=10:10:5000;%Store Range of Frequencies for Simulation u=zeros(n+1,nust+1);%

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

Triple the fundamental frequency, For the signal with four harmonics (first...

For the signal with four harmonics (first to fourth) that can be obtained from the script, do the following: a)  Place the time domain signal for the case in which all the harmo

Design of controller, Design a controller which regulates flow and compensa...

Design a controller which regulates flow and compensate pressure to my desire value in simscape.

Quiz2, 2)''dbcont'' command for debugging is used to Select one: a. Cont...

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

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