banner



How To Plot A Horizontal Line In Matlab

Plot a line MatLab

What is a line?

In Geometry, a line is a connection between 2 continuous points. So, a line is a connective path of 2 points. There should be a connection betwixt two points and the ii points should be continuous to plot a line. In graphs, a point tin take two or three axes depending on its dimension.

Suppose, y'all have 2 points and they are (x1, y1) = (two, 1) and (x2, y2) = (ii, 5). If we continuously connect these two points corresponding to the x-centrality and y-axis, then we will get a line. The line plotting has been blithe in the below figure.

Plot a line in Graph
Plot a line in Graph

Parametric equation of a line

The parametric equation to plot a circle in MatLab is also discussed on this site. The parametric equation of a line is used to generate continuous points between two initial points.

2nd parametric equation

10 = x0 + ganet

y = y0 + m2t

3D parametric equation

ten = 100 + m1t

y = y0 + chiliad2t

z = z0 + m3t

Slope intercept class of a line

The most not-vertical line generates by the slope-intercept class. In geometry, we are used this line grade to draw a line. It is mostly used in the linear regression algorithm.

y = mx + c

This is the slope-intercept equation of a line. Where x is an independent variable, y is a dependent variable, thousand is the slope, and c is a abiding value.

What is a vertical line?

A vertical line is a directed line where the value of 10 is constant. That means the value of the ten-axis is the aforementioned while the value of the y-axis will be incremented in a given range.

What is a horizontal line?

A horizontal line is a directed line where the value of y is constant.

What is a straight line?

A straight line is a ane-way directed line that is non curved at any point in a line. A straight line tin can be vertical or horizontal, or diagonal with respect to the x-axis and y-centrality.

straight line
vertical, horizontal, and diagonal straight line (left to right)

How to plot a line in MatLab?

Plotting a line in MatLab is simple. MatLab provides a pre-defined role to plot a line.

                      # to plot a 2D line
line (x, y)


# to plot a 3D line
line (x, y, z)

Lawmaking to plot a line in MatLab

                      %            point1            =                        [x1,            y1]
point1 = [ 1 , two ];

% point2 = [x2, y2]
point2 = [ 5 , 10 ];

% ploting the line using the 'line' function of matlab
line (point1,point2)

Output line

plot line in matlab figure
Output effigy of the above lawmaking

How to plot a vertical straight line in MatLab?

Yous can plot a vertical line in MatLab in three ways.

1. Plot a vertical line in MatLab using the 'line()' function

code

                      %            10 value            is            constant
10 = linspace ( 2 , 2 );

% y vlaues are independent to increment
y = linspace ( 3 , 10 );

% plot the x and y values in the 'line()'
line (10,y)

output figure

vertical line using 'line()' in matlab

2. Plot a vertical line in MatLab using 'plot()' function

lawmaking

                      %            ten value            is            constant
x = linspace ( 2 , 2 );

% y vlaues are independent to increase
y = linspace ( 3 , 10 );

% plot the x and y values in the 'line()'
plot (ten,y)
% turn on the grid mode for a clear view
grid on


output effigy

vertical line using 'plot()' in matlab

The lawmaking tin exist fabricated easier if we write it similar this,

                      %                        plot            ([x1,            y1], [x2,            y2])
plot ([ 1 , 1 ], [ five , 4 ])

3. Plot a vertical line in MatLab using 'xline()' role

The 'xline()' part of MatLab needs a constant x-axis value to plot a vertical line automatically.

code

                      xline            (            2            );        

output figure

plot vertical line using 'xline()' in MatLab


How to plot a horizontal straight line in MatLab?

It is piece of cake to plot a horizontal line in MatLab with a few lines of lawmaking like the plot of a vertical line.You need to exchange the 10-axis value with the y-axis value. Now, the value of y should be constant to plot a horizontal line in MatLab.

one. Plot a horizontal line in MatLab using the 'line()' office

lawmaking

                          %              x value              is              independent to increase
x = linspace ( 2 , x );

% y vlaue is constant
y = linspace ( 3 , three );

% plot the x and y values in the 'line()'
line (x,y)

output figure

plot horizontal line using 'line()'


ii. Plot a horizontal line in MatLab using 'plot()' role

code

                                  %                                    plot                  ([x1,                  y1], [x2,                  y2])
plot ([ 1 , 4 ], [ 5 , 5 ])

output effigy

3. Plot a horizontal line in MatLab using 'yline()' function

plot horizontal line using 'yline()'



Source: https://schoolofbeginners.blogspot.com/2022/03/plot-vertical-straight-line-matlab.html

0 Response to "How To Plot A Horizontal Line In Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel