9.6k views
4 votes
Assume the following commands have been entered in Matlab: >>t=0:0.1:3; >>x=t.sin(t); >>y=cos(t)+2sin(t); if you wanted to plot both x and y on the vertical axis of the same graph, which command(s) would you enter?

a) plot(t, [x, y])
b) plot(t, x); hold on; plot(t, y)
c) plot(x, y);
d) plot(t, x); plot(t, y)

1 Answer

1 vote

Final answer:

In Matlab, to plot both x and y against time t on the same graph, use 'plot(t, x); hold on; plot(t, y)' which uses the 'hold on' command to keep both plots on the same figure.

Step-by-step explanation:

To plot both x and y on the vertical axis of the same graph in Matlab with time (t) as the independent variable on the horizontal axis, you would use the following command: plot(t, x); hold on; plot(t, y).

This sequence of commands first plots the variable x against time, then holds the current figure so that the next plot is done on the same graph, and finally plots the variable y against time. The 'hold on' command is crucial as it allows for both lines to be plotted on the same figure without clearing the previous line.

User Elcadro
by
8.7k points