Plots Matlab

broken image


  1. Matlab Plot Matrix 2d
  2. Pole Zero Plots Matlab
  3. Plots Matlab
  4. Plots Matlab
  5. Bar Plots Matlab
  6. Plot A Function In Matlab
  7. Create Multiple Plots Matlab

This example shows how to create a variety of 3-D plots in MATLAB®. The mesh function creates a wireframe mesh. By default, the color of the mesh is proportional to the surface height. Z = peaks(25); figure mesh(z) Surface Plot. The surf function is used to create a 3-D surface plot. Typing plot(z) will plot the values of z against a list of 1,2,3,4,5, etc. You can choose the color of the points, the type of line used, and the shape of points used by adding a string following the arguments of plot. This would look something like plot(x,y,'r-p'). MATLAB Plots on Multiple Axes. We could also plot the above functions on different axes using the subplot function in MATLAB. The subplot function is used to tell MATLAB how to split up the figure window and where to place the graph from each successive plot command. Below shows MATLAB code for how to plot the functions on three separate.

  • Matlab Tutorial

MATLAB displays the Save As dialog box with the file type options. When you use the export button to save a plot, the output is tightly cropped around the axes content, including any legends or colorbars. The output does not include content outside the axes, such as other axes in the figure. Arranging multiple line plots in different subplot: Matlab supports to present the line plots generated in single execution, with distinct set of axes. The below example present 2 line plots generated from one singe execution of the program with two different set of axes. Slot magic app.

  • MATLAB Advanced
  • MATLAB Useful Resources
  • Selected Reading

To plot the graph of a function, you need to take the following steps −

  • Define x, by specifying the range of values for the variable x, for which the function is to be plotted

  • Define the function, y = f(x)

  • Call the plot command, as plot(x, y)

Following example would demonstrate the concept. Let us plot the simple function y = x for the range of values for x from 0 to 100, with an increment of 5.

Create a script file and type the following code −

When you run the file, MATLAB displays the following plot −

Let us take one more example to plot the function y = x2. In this example, we will draw two graphs with the same function, but in second time, we will reduce the value of increment. Please note that as we decrease the increment, the graph becomes smoother.

Create a script file and type the following code −

When you run the file, MATLAB displays the following plot − Nc casino boat.

Change the code file a little, reduce the increment to 5 −

MATLAB draws a smoother graph −

Adding Title, Labels, Grid Lines and Scaling on the Graph

MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to spruce up the graph.

  • The xlabel and ylabel commands generate labels along x-axis and y-axis.

  • The title command allows you to put a title on the graph.

  • The grid on command allows you to put the grid lines on the graph.

  • The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.

  • The axis square command generates a square plot.

Matlab Plot Matrix 2d

Example

Create a script file and type the following code −

MATLAB generates the following graph −

Drawing Multiple Functions on the Same Graph

You can draw multiple graphs on the same plot. The following example demonstrates the concept −

Example

Create a script file and type the following code −

MATLAB generates the following graph −

Matlab plots in latex

  • Define the function, y = f(x)

  • Call the plot command, as plot(x, y)

  • Following example would demonstrate the concept. Let us plot the simple function y = x for the range of values for x from 0 to 100, with an increment of 5.

    Create a script file and type the following code −

    When you run the file, MATLAB displays the following plot −

    Let us take one more example to plot the function y = x2. In this example, we will draw two graphs with the same function, but in second time, we will reduce the value of increment. Please note that as we decrease the increment, the graph becomes smoother.

    Create a script file and type the following code −

    When you run the file, MATLAB displays the following plot − Nc casino boat.

    Change the code file a little, reduce the increment to 5 −

    MATLAB draws a smoother graph −

    Adding Title, Labels, Grid Lines and Scaling on the Graph

    MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to spruce up the graph.

    • The xlabel and ylabel commands generate labels along x-axis and y-axis.

    • The title command allows you to put a title on the graph.

    • The grid on command allows you to put the grid lines on the graph.

    • The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.

    • The axis square command generates a square plot.

    Matlab Plot Matrix 2d

    Example

    Create a script file and type the following code −

    MATLAB generates the following graph −

    Drawing Multiple Functions on the Same Graph

    You can draw multiple graphs on the same plot. The following example demonstrates the concept −

    Example

    Create a script file and type the following code −

    MATLAB generates the following graph −

    Setting Colors on Graph

    MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their codes −

    CodeColor
    wWhite
    kBlack
    bBlue
    rRed
    cCyan
    gGreen
    mMagenta
    yYellow

    Example

    Let us draw the graph of two polynomials

    Pole Zero Plots Matlab

    • f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and

    • g(x) = 5x3 + 9x + 2

    Create a script file and type the following code −

    When you run the file, MATLAB generates the following graph −

    Setting Axis Scales

    The axis command allows you to set the axis scales. You can provide minimum and maximum values for x and y axes using the axis command in the following way −

    The following example shows this −

    Example

    Create a script file and type the following code −

    When you run the file, MATLAB generates the following graph −

    Generating Sub-Plots

    When you create an array of plots in the same figure, each of these plots is called a subplot. The subplot command is used for creating subplots.

    Syntax for the command is −

    where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular plot.

    Plots Matlab

    Each plot created with the subplot command can have its own characteristics. Following example demonstrates the concept −

    Plots Matlab

    Example

    Bar Plots Matlab

    Let us generate two plots −

    Plot A Function In Matlab

    y = e−1.5xsin(10x)

    y = e−2xsin(10x)

    Create a script file and type the following code −

    Create Multiple Plots Matlab

    When you run the file, MATLAB generates the following graph −





    broken image