DISCOVER
×
Loading ...

How to Plot a Horizontal Line in Matlab

Updated July 20, 2017

A horizontal line is a line whose points all share the same y-value. A horizontal line is perpendicular to a vertical line, whose points all share the same x-value. MATLAB is a technical computer program use for data processing and data visualisation. When plotting data it is often necessary to plot a horizontal line through a specific point to emphasise a particular point or area. Below shows an example of how to plot a horizontal line in MATLAB by defining the x and y-values that the horizontal line will pass through.

Loading ...
  1. Clear all active variables in the workspace by typing clear all in the command windows.

  2. Define the y-intercept value that the line will pass through. If the line is not meant to pass through the y-axis, define the height of the horizontal line. In this example, the height of the horizontal line will be 3, therefore type y=3 into the command window.

  3. Define the starting and ending points of the horizontal line by inputting the x-axis values into the command window. In this example, the line will start at -4 and end at 4 on the x-axis. Therefore enter x1=-4 and x2=4 into the command window.

  4. Plot the horizontal line by entering plot([x1, x2], [y1, y1]) into the command window. This will plot a horizontal line that runs from the points (-4,3) to (4,3). Since both y values are the same, the line will be horizontal.

  5. Tip

    A vertical line can be plotted in the same manor by keeping the x-values constant and changing the y values.

Loading ...

About the Author

Michael Peter has been a technical writer since 2006 for a power/start-up company and has published scientific papers in research journals including "Analytical Chemistry" and "Electrochimica Acta." He holds a Bachelor of Science in mechanical engineering and is currently completing his Ph.D. related to nano/microfludics and spectroscopy.

Loading ...