Question

1- Create a new script that is called HW9.m and save it. The script will do...

1- Create a new script that is called HW9.m and save it. The script will do the following. Test your code for each of the cases and upload your script as a .m file. [15 points]

a. Create a random integer numbers that goes from 0 to 5 and assign it to a variable y using rand and round commands. Hint: Note that rand function only creates random number between 0 and 1. You need to scale the values to get random numbers from 0 to 5 (multiply by 5). You also need to round the generated random numbers to get an integer value. Use round command [5 points]

b. Use a switch-case statement that would switch on y such that it will evaluate the following cases: [10 points]

i. Case 0 → display ‘The random number is 0’

ii. Case 2 → display ‘The random number is 2’

iii. Case 4 → display ‘The random number is 4’

iv. Otherwise → display ‘The random number is odd’

Homework Answers

Answer #1

(a). Use the following sequence of commands to obtain the required results in MATLAB:

X=rand(1,5) %generates random array of size 1x5 each lying in the rane of 0 to 1.
p=5*X %Takes the random values of y in the range of 0 to 5
y=round(p) %Rounds of the given values to nearest integer.

(b). The switch statement can be used to obtain the required output as follows:

switch y
case 0
disp('The random number is 0.')
case 2
disp('The random number is 2.')
case 4
disp('The random number is 4.')
otherwise
disp('The random number is odd.')
end

Write the above code just after the code of part a. Else you will have to mention the value of y just above this code.

Hope the answer was helpful. Feel free to comment if the problem still persists.

Your feedbacks help us perform better. Please upvote the answer if it was helpful.

Thank you!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
1) Create one php file with the 4 parts. Each part should do the following: The...
1) Create one php file with the 4 parts. Each part should do the following: The 1st part of the script implements a while loop that displays odd numbers between 1 and 15. The 2nd part of the script implements a for loop to display numbers between 10 and 20 The 3rd  part of the script includes the following variable declaration: $sales = 5000; Using if/elseif/else statement determine the bonus percent. Make sure to change the value of $sales to fully...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
I need to make some modifications to the code below. Numbers 1 through 3 are the...
I need to make some modifications to the code below. Numbers 1 through 3 are the required modifications. 1. Write a static method to have the players guess what was rolled 2. If guessed what was rolled you get 10 points 3. You win if you reach 30 points before the end of the round otherwise the person with the points wins at the end of five rounds The code is below import java.util.Scanner; public class ChoHan { public static...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
Your C program will do the following : Must use at least 2 function prototypes &...
Your C program will do the following : Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays. 1. In your main program, create a array of size 7 X 7. 2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function...
Step 1: Create a new Java project in NetBeans called “PartnerLab1” Create a new Java Class...
Step 1: Create a new Java project in NetBeans called “PartnerLab1” Create a new Java Class in that project called "BouncyHouse" Create a new Java Class in that project called “Person” Step 2: Implement a properly encapsulated "BouncyHouse" class that has the following attributes: Weight limit Total current weight of all occupants in the bouncy house (Note: all weights in this assignment can be represented as whole numbers) …and methods to perform the following tasks: Set the weight limit Set...
Complete the following program. This program should do the following: 1. Creates a random integer in...
Complete the following program. This program should do the following: 1. Creates a random integer in the range 10 to 15 for variable: allThreads, to create a number of threads. 2. Creates a random integer for the size of an ArrayList: size. 3. Each thread obtains a smallest number of a segment of the array. To give qual sized segment to each thread we make the size of the array divisible by the number of threads: while(size%allThreads != 0)size++ 4....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT