2- Create a new script that is called HW10b.m and save it. The script will do th
ID: 2074563 • Letter: 2
Question
2- Create a new script that is called HW10b.m and save it. The script will do the following: Create a random number that goes from 0 to 5 and assign it to a variable y using the following command a. y round(rand(1,1)*5) b. Use a switch-case statement that would switch on y such that it wil evaluate the following cases: 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' c. Test your code for each of the cases and upload your script as a.m file.Explanation / Answer
% Below is the matlab code
clc
clear all
close all
y=round(rand(1,1)*5);
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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.