0% found this document useful (0 votes)
17 views6 pages

Proposed Questions For Arrays and Matrices in MATLAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Proposed Questions For Arrays and Matrices in MATLAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. What is the result of the following MATLAB code statements?

---------------------------------------
A = [1 2 3; 4 5 6; 7 8 9];
B = A(2:end, 1:2);
---------------------------------------
a) B = [2 3; 5 6; 8 9]
b) B = [1 2; 4 5; 7 8]
c) B = [4 5; 7 8; 9]
d) B = [2 3; 5 6]

*Answer: a) B = [2 3; 5 6; 8 9]*

2. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [A; B];
---------------------------------------
a) C = [1 2; 3 4; 5 6; 7 8]
b) C = [1 2 5 6; 3 4 7 8]
c) C = [1 2; 3 4 5 6; 7 8]
d) C = [1 2 3 4; 5 6 7 8]

*Answer: a) C = [1 2; 3 4; 5 6; 7 8]*

3. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A';
---------------------------------------
a) B = [1 2 3 4]
b) B = [1 3; 2 4]
c) B = [1 2; 3 4]
d) B = [1 3; 2 4;]

*Answer: b) B = [1 3; 2 4]*

4. How can you access the last element of a vector in MATLAB?


a) Using the ‘end’ keyword.
b) Using the index ‘-1’.
c) Using the ‘last’ keyword.
d) There is no direct way to access the last element.

*Answer: a) Using the ‘end’ keyword.*


5. What is the result of the following MATLAB code statements?
---------------------------------------
A = [1 2; 3 4];
B = sum(A);
---------------------------------------
a) B = [4 6]
b) B = 10
c) B = [1 2 3 4]
d) B = [3 7]

*Answer: a) B = [4 6]*

6. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A(:);
---------------------------------------
a) B = [1; 2; 3; 4]
b) B = [1 2; 3 4]
c) B = [1 3; 2 4]
d) B = [1; 3; 2; 4]

*Answer: a) B = [1; 2; 3; 4]*

7. What does the MATLAB function ‘sort’ do?


a) Sorts the elements of a matrix in ascending order.
b) Sorts the rows of a matrix in ascending order.
c) Sorts the columns of a matrix in ascending order.
d) There is no built-in function for sorting matrices in MATLAB.

*Answer: a) Sorts the elements of a matrix in ascending order.*

8. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = [5 6; 7 8];
C = A .* B;
---------------------------------------
a) C = [5 6; 21 32]
b) C = [6 12; 21 32]
c) C = [5 12; 21 32]
d) C = [5 12; 21 32;]

*Answer: c) C = [5 12; 21 32]*


9. What is the result of the following MATLAB code statements?
---------------------------------------
A = [1 2 3; 4 5 6; 7 8 9];
B = A(1:2, 1:2);
---------------------------------------
a) B = [1 2; 4 5]
b) B = [1 2 3; 4 5 6]
c) B = [1 4; 2 5]
d) B = [1 2; 4 5;]

*Answer: a) B = [1 2; 4 5]*

10. How can you compute the dot product of two vectors in MATLAB?
a) Using the ‘dot’ function.
b) Using the ‘.*’ operator.
c) Using the ‘cross’ function.
d) There is no built-in function for computing the dot product.

*Answer: a) Using the ‘dot’ function.*

11. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A + 3;
---------------------------------------
a) B = [4 5; 6 7]
b) B = [1 2; 3 4]
c) B = [4 6; 6 7]
d) B = [4 5; 6 7;]

*Answer: a) B = [4 5; 6 7]*

12. How can you find the maximum element in a matrix along a specified dimension in MATLAB?
a) Using the ‘max’ function.
b) Using the ‘maxelement’ function.
c) Using the ‘maxdim’ function.
d) There is no built-in function for finding the maximum element along a specified dimension.

*Answer: a) Using the ‘max’ function.*

13. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A';
C = B';
---------------------------------------
a) C = [1 2; 3 4]
b) C = [1 3; 2 4]
c) C = [1 2 3 4]
d) C = [1 3; 2 4;]

*Answer: a) C = [1 2; 3 4]*

14. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = sum(A, 2);
---------------------------------------
a) B = [3; 7]
b) B = 10
c) B = [1 2; 3 4]
d) B = [3 7]

*Answer: a) B = [3; 7]*

15. How can you compute the element-wise square root of a matrix in MATLAB?
a) Using the ‘sqrt’ function.
b) Using the ‘.^’ operator.
c) Using the ‘power’ function.
d) There is no built-in function for computing the element-wise square root.

*Answer: a) Using the ‘sqrt’ function.*

16. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A.^2;
---------------------------------------
a) B = [1 4; 9 16]
b) B = [1 2; 3 4]
c) B = [1 4 9 16]
d) B = [1 2; 3 4;]

*Answer: a) B = [1 4; 9 16]*

17. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2 3; 4 5 6; 7 8 9];
B = sum(A(:));
---------------------------------------
a) B = 45
b) B = [12 15 18]
c) B = 15
d) B = [6 15 24]
*Answer: a) B = 45*

18. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A(2, :);
---------------------------------------
a) B = [2 4]
b) B = [1 3; 2 4]
c) B = [3 4]
d) B = [1 2]

*Answer: a) B = [2 4]*

19. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A(1, :);
C = A(:, 2);
---------------------------------------
a) B = [1 2]; C = [2 4]
b) B = [1 3]; C = [2 4]
c) B = [1 2]; C = [3 4]
d) B = [1 3]; C = [4 4]

*Answer: a) B = [1 2]; C = [2 4]*

20. How can you compute the element-wise division of two matrices in MATLAB?
a) Using the ‘/’ operator.
b) Using the ‘./’ operator.
c) Using the ‘div’ function.
d) There is no built-in function for element-wise division.

*Answer: b) Using the ‘./’ operator.*

21. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A(1:end-1, :);
---------------------------------------
a) B = [1 2]
[3 4]
b) B = [1 2 3 4]
c) B = [1 3; 2 4]
d) B = [1 2]
*Answer d) B = [1 2]*

22. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A([2 1], :);
---------------------------------------
a) B = [3 4; 1 2]
b) B = [1 2; 3 4]
c) B = [2 1; 4 3]
d) B = [3 4]

*Answer: a) B = [3 4; 1 2]*

23. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2 3; 4 5 6; 7 8 9];
B = A(:, end:-1:1);
---------------------------------------
a) B = [3 2 1; 6 5 4; 9 8 7]
b) B = [9 8 7; 6 5 4; 3 2 1]
c) B = [1 4 7; 2 5 8; 3 6 9]
d) B = [7 8 9; 4 5 6; 1 2 3]

*Answer: a) B = [3 2 1; 6 5 4; 9 8 7]*

24. What is the result of the following MATLAB code statements?


---------------------------------------
A = [1 2; 3 4];
B = A';
C = A * B;
---------------------------------------
a) C = [5 11; 11 25]
b) C = [5 11; 11 25;]
c) C = [5 11]
[11 25]
d) C = [5 11; 11 25;]

*Answer: a) C = [5 11; 11 25]*

You might also like