MATLAB Questions and Answers Part-22

1. What is the output of the following code?
title(‘x^2+y^2=r^2’)
a) x2+y2 = r2
b) x^2+y^2 = r^2
c) Error
d) No such command

Answer: a
Explanation: The ‘^’ is used, in the title command, to place the number as an exponent. Hence, option x2+y2 = r2 is correct. The rest of the options are incorrect

2. What is the output of the following code?
t=linspace(0,3*pi);p=sin(t);y=cos(t);plot(t,p,t,q);
a) Error
b) Multiple plots
c) A unit circle
d) A sinusoidal

Answer: b
Explanation: The plot command can be used to plot multiple graphs in a single window without using the hold command. The above code plots two sinusoidal curves from 0 to 3*pi. A unit circle would’ve been plotted if the plot command had only p and q as input.

3. What is the default range used by the fplot command?
a) [-5,5]
b) (-5,5)
c) No default range
d) No such command

Answer: a
Explanation: The fplot command is almost like the ezplot command. It will plot the graph of y=f(x) within an interval [-5,5] as it was defined. This default range can be changed by giving a separate vector input to the fplot() command.

4. How can we group the elements in a 3-d bar graph?
a) Give ‘grouped’ as style input to bar3() command
b) Give ‘grouped’ as style input to bar() command
c) Give ‘group’ as style input to bar3() command
d) Give ‘group’ as style input to bar() command

Answer: a
Explanation: A 3-d bar graph is created with the bar3() command. The elements of each row of the input vector can be grouped together by giving a string input ‘grouped’ to the bar3() command.

5. What is the size of the z vector in a mesh(x,y,z) if the sizes of x and y vectors are m, n respectively?
a) [m,n]
b) (m,n)
c) [m,n)
d) Independent of m and n

Answer: a
Explanation: The size of the z vector is dependent on the size of the x and vectors. The permissible size lies between [m,n] and hence [m,n] is correct.

6. What is the purpose of the figure command?
a) Opens a blank window
b) Opens a blank window to draw graphs
c) Opens a window containing axes
d) Opens a window containing grid and axes

Answer: b
Explanation: The figure command simply opens a separate blank window where new graphs are about to be plotted. It does not contain any axes or grid unless mentioned.

7. What is the range of co-ordinates obtained of the following code?
[x,y]=meshgrid(4)
a) 1:4 in x and y co-ordinates
b) 0:4 in x & y co-ordinates
c) only 4 in x and y co-ordinate
d) Error

Answer: c
Explanation: Since the input is not a vector, only one co-ordinate will be assigned to both x and y. Hence only 4 will be assigned to x and y as the co-ordinate.

8. What is the nature of z in surf(x,y,z)?
a) Integer
b) Vector
c) Matrix
d) String

Answer: c
Explanation: The final input to the surf command, z, should be a matrix. The matrix is computed for each co-ordinate generated and given input interms of x and y.

9. What is the RGB triplet style for yellow?
a) [1 1 0]
b) [1 0 1]
c) [1 0 0]
d) [0 1 1]

Answer: a
Explanation: The RGB triplet specifies the intensity of Red, Yellow and Green for a user-specified color input to the surf command. For yellow, it is defined in MATLAB as [1 1 0].

10. What is the range of RGB triplets for the surf command?
a) [1 0]
b) [0 1]
c) (0 1)
d) (0 1]

Answer: b
Explanation: The range of RGB triplets for the surf command is pre-defined in MATLAB as [0 1]. If any other value is given as input, MATLAB will give an error