# How to Plot a Horizontal Line in Matlab

Techwalla may earn compensation through affiliate links in this story.
A horizontal line is a line whose points share the same y-value.

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 visualization. When plotting data it is often necessary to plot a horizontal line through a specific point to emphasize 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.

## Step 1

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

Video of the Day

## Step 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.

## Step 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.