MATLAB Questions and Answers Part-25

1. What is the output of the following command?
T=[-1:1:90];plot(T,T,’G’)
a) A green ramp function
b) Error
c) A grey ramp function
d) A ramp function

Answer: a
Explanation: There is no error in the above code. It will generate a green colored ramp function.

2. What is the output of the above code?
T=[-1:1:90];plot(T,T,’-o’, 'MarkerIndices',1:6:length(T))
a) A green ramp function
b) A ramp function with y value marked at lengths of 5
c) A ramp function with y value marked
d) A ramp function with y value marked at lengths of 6

Answer: b
Explanation: The above code will plot a ramp function and mark the y values separated by 5 units from the initial value.

3. What is the output of the following code?
t=[0:.1*pi:pi];plot(t,sin(t),’MarkerIndices’,1:rms(sin(t)):length(sin(t))
a) Error
b) A sinusoid
c) A half wave sinusoid marked at interval of r.m.s. values
d) A green colored sinusoid

Answer: a
Explanation: The interval for marking cannot be fractional. It has to be an integer and hence the above code will result in an error.

4. The fill command cannot take more than ______ inputs.
a) 1
b) 3
c) 2
d) Many

Answer: c
Explanation: The fill command ca only take 2 inputs. MATLAB will return an error if more than 2 inputs are given to the fill command.

5. What is the output of the following code?
t=0:.000001:pi;x=sin(t);y=cos(t);fill(x,y)
a) An ellipse
b) Error
c) A semi-circle
d) A sinusoid

Answer: b
Explanation: One less input has been given to the fill command. The color is to be mentioned in the input of the fill command or MATLAB will give an error.

6. What is the output of the following code?
w=[0:.1*pi:2*pi];plot(w,sin(w),’ ’)
a) A sinusoid
b) A blank graph
c) Error in plot command
d) A sinusoid with a phase difference

Answer: a
Explanation: The output of the above code will only be a sinusoid. The input to within the ‘’ is empty so the default style of plotting with – will be used by the plot command.

7. What does the set command do?
a) The operation of the fill command
b) The operation of changing intervals of axes
c) The operation of the plot command
d) The operation of the figure command

Answer: b
Explanation: The set command can edit the graphics objects created in MATLAB. It cannot plot a graph hence it does not perform the operation of the plot, stem or the figure command.

8.What is the nature of the 2nd vector input in the following command?
set( X,vector_1, vector _2 );
a) a m*n matrix where m=length( vector_1 )
b) a m*n matrix where n=length( vector_1 )
c) a m*n matrix where m>length( vector_1 )
d) a m*n matrix where n>length( vector_1 )

Answer: a
Explanation: The number of rows is equal to the number of inputs given into vector 1. The number of columns is equal to the number of elements in X.

9. A semi-log graph cannot be plotted in MATLAB.
a) True
b) False

Answer: b
Explanation: The scales of the axes can be converted to a linear and logarithmic scales with the set command. Hence, the above statement is false.

10. What is the output of the following code?
t=[-2:1:2];plot(t,t);ax=gca;ax.Xscale=’Logarithmic’;
a) Error
b) Syntactical error
c) A semi-log graph of a ramp function
d) A ramp function

Answer: a
Explanation: The Xscale property recognizes Logarithmic as a log. Hence, there is an error in the above code while assigning the x-axis logarithmic.