Question

In: Computer Science

MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one...

MATLAB:

Matrix M = [ 0 2 3 5; 7 3 8 4 ]

Write one command that stores all of the rows of columns 1, 2, and 3 of M into a matrix named M2.

Solutions

Expert Solution

Hello, so, we have our matrix M, given in the question -

M = [ 0 2 3 5; 7 3 8 4 ]

let us see how it will look like -

M will look like 

   1st     2nd     3rd     4th
  column  column  column  column
[   0       2       3       5
    7       3       8       4   ]

Now after storing all of the rows of columns 1, 2, and 3 of our given matrix M, our desired matrix will look like

M2, which is our desired matrix = 

   1st      2nd     3rd
  column   column  column
[    0       2       3
     7       3       8   ]

So, you see, only rows of the column 1, 2, and 3 are there.

Now the one-line command, which we can use to make it work is -

M2 = M(:, 1:3)

It simply means that we are making a matrix M2, which will store all the row values of matrix M, and column values starting from index or position 1st to 3rd.

In M(:, 1:3), M is our matrix, and the first parameter after the parenthesis is the row value, where we have specified ':', which means all the rows (':' means all the values), and the second parameter separated by a comma (,) is our column value, which we are giving '1:3', means take column values from index 1 to 3, or better say take values from 1st column to 3rd column.

So, our full code will look like this -

M = [ 0 2 3 5; 7 3 8 4 ]

M2 = M(:, 1:3)

The result -

Hope you like my answer, and if you like, then please do upvote this answer, and also hope that you now know how to do it, and if you feel that you are stuck at some point, then please do comment and I will clarify it as soon as possible.

Happy Learning. Thank you.


Related Solutions

A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5 3 0 2 5 4 1 6 9 5 3 1 2 10 6 1 1 2 1 19 6 6 6 7 0 4 1 1 1 0 1 9 2 2 2 1 16 10 10 5 2 3 1 4 4 4 3 6 2 8 5 2 7 1 6 4 0 3 1 1 1 Background: A group of...
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write...
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write a list comprehension to extract the first column of the matrix [1, 4, 7]. Write another list comprehension to create a vector of twice the square of the middle column.
first matrix A [ 2 -1 3 ] [-4 0 -2 ] [2 -5 12 ]...
first matrix A [ 2 -1 3 ] [-4 0 -2 ] [2 -5 12 ] [4 0 4 ] amd b [2] [-2] [5] [0] solve for Ax=b using tan LU factorization of A
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1...
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1 9 2 13 3 14 4 13 5 18 What are the confidence limits (alpha = 0.05) for the true mean value of Y when X = 3?
Given the matrix as shown below n_array = 3 1 8 3 5 7 4 9...
Given the matrix as shown below n_array = 3 1 8 3 5 7 4 9 2 Write a M-file script program that generates this n_array, and answer each question using one line of MATLAB statement. a) Replace the second column of the n_array with a column of 0s b) Replace the element in the second-row, third-column with a zero c) Change the n_array to a 4 x 3 array by adding a row of 0s The end result for...
Let 3x3 matrix A = -3 0 -4                               0 5 0        &nb
Let 3x3 matrix A = -3 0 -4                               0 5 0                              -4 0 3 a) Find the eigenvalues of A and list their multiplicities. b) Find a basis, Bi, for each eigenspace, E(i). c) If possible, diagonalise matrix A. (i.e find matrices P and D such that Pinv AP = D is diagonal).
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6 13 7 33 8 42 9 66 10 77 11 105 12 103 13 110 14 105 15 84 16 70 17 51 18 40 19 27 20 27 21 15 22 5 23 7 24 2 25 2 26 1 27 0 28 0 29 0 30 0 (7) On the Histogram worksheet, calculate all frequencies of the distribution using the table shown....
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
Data: 7,-5, -8, 7, 9, 15, 0, 2, 13, 8, 6, -2, 4 (a) Mean= Mode=...
Data: 7,-5, -8, 7, 9, 15, 0, 2, 13, 8, 6, -2, 4 (a) Mean= Mode= median= (b) Variance= Standard deviation= (c) Range= IQR(Interquartilerange)= (d) Mid-Range= Mid-Hinge=
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT