This set of MATLAB Interview Questions and Answers for freshers focuses on “Vectors and Matrices – 2”.

1. What is the output of the following code?

A=[1 2 3.. ];

a) The output is suppressed

b) A row vector

c) A row vector concatenated with a null matrix

d) Error

View Answer

Explanation: The above code will give in an error due to the fact that ellipsis hasn’t been done properly. There should’ve been a semi-colon after 3 and we need to give 3 dots. Thereafter, option “the output is suppressed” is actually correct because the output would essentially be suppressed while a row vector A gets stored in the workspace.

2. What is the output of the following code?

A=[1 2 a..; ];

a) Error due to a

b) Error due to A

c) Error due to [];

d) Error due to ;

View Answer

Explanation: Typically, the row vector A contains integers as the first element and thus the entire array becomes an integer vector. But the inclusion of a results in an error since a is a character. If, however, a was written within ‘’, there wouldn’t have been a error.

3. What is the output of the following code?

A=[1 2 ‘a’;… ];

a) Error due to ‘a’

b) Error due to ‘…’

c) Error due to []

d) ‘a’

View Answer

Explanation: MATLAB would show such kind of an output since the A vector gets defined as a character array when a gets defined within ‘’. The syntax for ellipsis is correct and there is no error.

Output: ‘a’

4. What is the output of the following code?

A=[1 2 ‘a’;… ‘f’ ‘q’ ‘w’];

a) A 2*3 character array

b) A 3*2 character matrix

c) A 3*2 character vector

d) A 2*3 character vector

View Answer

Explanation: The above code performs ellipsis to concatenate two matrices vertically. Thus, the output is a 2*3 matrix since the dimension of each vector, it concatenates, is 3. Now, the presence of a character makes the vector character vectors.

5. What is the output of the following code?

A=[1 2 ‘a’;… ‘f’ ‘q’ ‘w’;… ]];

a) Syntax Error

b) A 2*3 character matrix

c) The concatenation of 2 vectors, vertically, with size 3

d) Cannot be determined

View Answer

Explanation: There are two ]] at the end. This leads to an error. This is because only one ] was sufficient to produce A as defined in the option concatenation of 2 vectors, vertically, with size 3. But the usage of an extra ] leads to an error the code.

6. What is the output of the following code?

A=[1 2 ‘a’…; ‘a’ ‘b’ ‘c’;… ];

a) Error in syntax

b) A 3*2 matrix of characters

c) Error due to 1 and 2

d) Error due to a

View Answer

Explanation: Ellipsis has been written wrong in the first line. This is because there has to be 4 ‘.’ for concatenating vectors row-wise. Since we’ve not used 4 dots, it leads to an error.

7. What is the output of the following code?

A=[1 2 ‘a’….; ‘a’ ‘b’ ‘c’;… ];

a) A 1*6 matrix

b) A 6*1 matrix

c) Error in the code

d) Error in ellipsis

View Answer

Explanation: In the above code, ellipsis is done to concatenate two vectors row-wise. There is no error in the syntax ad the output A 1*6 matrix.

8. What is the output of the following code?

clear ALL

a) Clears the workspace

b) Clears the matrices

c) Clears the vectors

d) Clears ALL

View Answer

Explanation: The following code clears the variable ALL from the workspace. Notice that it won’t give an error even if the ALL variable is not present in the workspace. The correct option is Clears ALL.

9. All matrices are vectors but all vectors are not matrices in MATLAB.

a) True

b) False

View Answer

Explanation: If a=[], a is a matrix but not a vector in MATLAB. Hence, the above statement is true.

10. What is the output of the following code?

ismatrix([]);

a) logical 1

b) logical 0

c) logical -1

d) Error

View Answer

Explanation: The ismatrix(0 function returns a logical 1 if the size of the input vector is [m,n] where m,n is non-negative. This is important to remember. The size of [] is 0*0 which is non-negative. Hence, the output is 1.

11. What is the output of the following code?

isvector([]);

a) 1

b) 0

c) Syntactical error

d) Logical error

View Answer

Explanation: The isvector() command typically would return a 0 is the input is a null vector. Hence, the output of the above code is 0.

12. If the dimensions of vectors don’t match, the plot command will always give an error.

a) True

b) False

View Answer

Explanation: In the following case: plot([a],[1:10]), the plot command takes x as [a-1:.2:a+1]. Hence, the above statement is not true. A graph will eventually get plotted.

**Sanfoundry Global Education & Learning Series – MATLAB.**

To practice all areas of MATLAB for Interviews, __here is complete set of 1000+ Multiple Choice Questions and Answers__.