Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE MATLAB PROGRAM Create a function that generates random arrays of integers be

ID: 2083595 • Letter: U

Question

USE MATLAB PROGRAM

Create a function that generates random arrays of integers between a and b. Use the definition line function. A = randinteger (a, b, M, N) where a and b define the (inclusive) range and M and N define the size of the output array (rows and columns, respectively) a) Using the function create a 5 times 5 matrix of random integers between 1 and 10 b) in the matrix created in part (a) change all the even numbers to 2. c) Using the function create a 1 times 16 matrix of random integers between -5 and 10 d) In the matrix from part (c) make all that are less than the mean to zero.

Explanation / Answer

a)

From the given randinteger function in matlab we can use “randi”.

Then:

r = randi([1 10],5,5)

then

5X5 matrix will be resulted.

r =

    7    4    3    4    6

    3    3    6   10    5

    1    6    7   1    7

    3   10    6    8    8

    9    1    9    7    6

b)

We need to change all even numbers to 2

r =

    7    2    3    2    2

    3    3    2   2    5

    1    2    7   1    7

    3   2    2    2    2

    9    1    9    7    2

c)

As per given information the matlab code and results are:

Then the numbers less then 3.125 will be zeros