Which code can be used for changing the dimensions of a matrix as follows? Input matrix: 1 2 3 Output matrix: 1 4 2 5 3 6

Which code can be used for changing the dimensions of a matrix as follows?
Input matrix: 1 2 3 Output matrix: 1 4 2 5 3 6
4 5 6
A. reshape([1,2,3;4,5,6],1,6)
B. reshape([1,2,3;4,5,6];1;6)
C. reshape([1,2,3;4,5,6]:1:6)
D. reshape([1,2,3;4,5,6],6,1)
 
Answer: a
Explanation: There is a pre-defined function in MATLAB which allows the user to change the dimensions of a matrix without much to be done. The function is ‘reshape(A,row,column)’ where A is the original matrix, row denotes desired rows while column denotes desired columns. Now, the matrix A is defined in MATLAB as A=[1,2,3;4,5,6], but we don’t need to do it explicitly. We can put it directly within the function and henceforth put the desired row and columns required( here 1 and 6).
 

Tìm kiếm

Back
Top