MATLAB Questions and Answers Part-24

1. What is the output of the following code?
t=linspace(0:.1*pi:2*pi);plot(t,sin(t));text(0.5,1,’Ho !’,’colour’,’red’)
a) Error
b) A graph with Ho! written
c) A An inverted sinusoid
d) An inverted sinusoid with Ho written

Answer: a
Explanation: The text property added in the above code is ‘Colour’. This is the error, it should’ve been ‘color’. Then the output of the following code would’ve been A graph with Ho! written

2. What is the output of the following code?
t=linspace(0:.19*pi:27*pi);plot(t,sin(t));text(0.5,1,’color’,’red’)
a) Error on plot command
b) Error in linspace command
c) Error in text command
d) A graph of a sinusoid with Ho ! written on it.

Answer: b
Explanation: The inputs to the linspace command are to be separated by a semi-colon. Here, MATLAB will give an error because the inputs are separated by a :.

3. What is the output of the following code?
t=linspace(0,.00002*pi,2*pi);plot(t,cos(t));text(0.5,1,'color','blue')
a) Syntactical Error due to text command
b) Input error due to text command
c) Error in linspace command
d) A graph of sinusoid with Ho ! written on it

Answer: a
Explanation: We haven’t given any string input to the text command which we want to show in the graph. Hence, MATLAB will send an error due to the text command. The rest of the code is okay

4. What is the output of the following command?
t=linspace[0,20*pi,2*pi];plot(t,tan(t));text(0.5,1,'Ho!','color','blue')
a) Syntactical error in the text command
b) Error in input of plot command
c) Error in linspace command
d) The graph of tan(t) w.r.t. t with Ho ! writted

Answer: c
Explanation: The input to the linspace command should be within a parentheses. Here, we’ve used [] so MATLAB will give an error.

5. What is the output of the following code?
t=linspace(0,.5,2*pi);plot(t,sin(t));text(0.5,1,'\mu Ho!','color','blue')
a) A sinusoid with µHo! written
b) A sinusoid with Ho! written
c) Error in the text command
d) A sinusoid with \mu Ho! written

Answer: a
Explanation: The interpretation of \mu is µ and hence A sinusoid with µHo! written is correct. There is no error in the text command.

6. What is the output of the following code?
t=[-10:1:10];plot(t,t), text(0,0,’Origin’,color,’blue’)
a) A ramp function with Origin written in Blue
b) A ramp function with Origin written in Blue and center left alignment
c) Error
d) A ramp function with Origin

Answer: a
Explanation: It displays a ramp function with Origin written in Blue.

7. The text given to the graphs can be made bold.
a) True
b) False

Answer: a
Explanation: The texts given to the graph can be made bold by giving \bf and the writing the text which we want to make it bold. Hence, the above statement is true.

8. The font style of the input text can be changed by the ____
a) fontname{}
b) fontstyle{}
c) fontname()
d) fontname[]

Answer: a
Explanation: The desired fontname could be given in the style denoted by fontname{}, to the text command. This will change the font of the text printed in the graph

9. What is the output of the following code?
t=[-10:1:10];plot(t,3*t), text(0,0,’Origin’,color,’blue’,’verticalalignment’,’left’)
a) A ramp function with Origin written in Blue and left alignment
b) A ramp function with Origin written in Blue
c) A ramp function with Origin written in Blue and center left alignment
d) Error

Answer: d
Explanation: The left is not the correct value for vertical alignment. The correct values are namely ‘center’, ‘base’, ‘middle’, ‘top’. Hence, the above code will only give an error.

10. The default colour of graph generated by the plot command is blue.
a) True
b) False

Answer: a
Explanation: The default color of the graph generated by the plot/stem command is blue. I tcan be changed from the plot command itself or the set command.