

When plotting many things on the same graph it
#Plot function matlab series#
With the sine wave as a solid red line and the cosine wave as a series of green x's.īy adding more sets of parameters to plot, you can plot as many different data sets on the same figure as you want. The following m-file will plot a sine wave and cosine wave, Same set of axes, using a different color and style for each. Let's say you want to plot a sine wave and cosine wave on the

You can also plot more than one function on the same figure. Of colors, point markers, and line styles are summarized below. The third input consists of one to three characters which specify a color, point marker type, and/or line style. For example, to plot the above function as a red, dotted line, change the m-file as follows to generate the figure The color, point marker, and line style can be changed on a plot by adding a third parameter (in single quotes) to the plot command. (on the horizontal axis) versus the imaginary part (on the vertical axis). If the input vector contains complex numbers, MATLAB plots the real part of each element Vector will be used for the horizontal axis). In that case the vector columns are plotted versus their indices (the The plot command can also be used with just one input vector. MATLAB can plot a 1 x n vector versus an n x 1 vector, or a 1 x n vector versus a 2 x n matrix (you will generate two lines), as long as n is the same for both vectors. One thing to keep in mind when using the plot command is that the vectors x and y must be the same length.

#Plot function matlab code#
If we wished to plot this function, we could create an m-file with the following code to generate the basic plot shown below. Consider the following simple, linear function.
#Plot function matlab how to#
The default is that each time the plot command is issued, the current figure willīe erased we will discuss how to override this below. This command will plot the elements of vector y (on the vertical axis of a figure) versus the elements of the vector x (on the horizontal axis of the figure). This code can be entered in the MATLAB command window or run from an m-file. The basic syntax of the function call is shownīelow. The plot command also happens to be one of the easiest functions to learn how to use. One of the most important functions in MATLAB is the plot function.
