Create a 4 times 4 matrixG of random integers between 1 and

Create a 4 times 4 matrix(G) of random integers between 1 and 30 using the command: G = randi(30. 4, 4) Find the elements in G whose values are greater than 12 Find the sum of all the values in G Find the sum of all the values in the first row Find the sum of all the values in the second row

Solution

>> G=randi(30,4,4)

G =

13 20 21 20
28 2 23 6
24 26 23 22
29 29 12 1

>> G>12

ans =

1 1 1 1
1 0 1 0
1 1 1 1
1 1 0 0

>> sum(sum(G))

ans =

299

>> sum(G(1,:))

ans =

74

>> sum(G(2,:))

ans =

59

 Create a 4 times 4 matrix(G) of random integers between 1 and 30 using the command: G = randi(30. 4, 4) Find the elements in G whose values are greater than 12

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site