How to Draw a Line in a Plot Matlab

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

  • Forums
  • EDA Theory
  • Elementary Electronic Questions
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

[Matlab] How to draw a line in plot?

  • Thread starter davyzhu
  • Start date
Status
Not open for further replies.
  • #1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
matlab plot line

Hello all,

How to draw a line in plot when I know the start point(x1,y1) and end point(x2,y2)?

Thanks!
Davy

  • #2
Joined
Jul 22, 2004
Messages
466
Helped
85
Reputation
168
Reaction score
39
Trophy points
1,308
Activity points
3,334
matlab draw line

Hej Davy

Lets say you want a line with coordinates (x1,y1) and (x2,y2). Then you make a vector with the x and y coordinates: x = [x1 x2] and y=[y1 y2].
Matlab has a function called 'Line', this is used in this way:
line(x,y)
I generates a plot with the two points and a line that connects them.

Hopes this helped.

Regards

  • #3

mhamed

Advanced Member level 4
Joined
Jul 28, 2004
Messages
114
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
827
plot line matlab

no line function is neccessary. plot byitself make an linear interpolation between points so only try
plot([x1,x2],[y1,y2]).

  • #4
Joined
Sep 5, 2007
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
draw line matlab

Hello!

I got a similar problem

I want to form my initials (JCBD) but with a custom path. So I need to put some points in a plot and them connect them with lines so that the 4 letters are formed

how do I do this?

  • #5
Joined
Feb 14, 2008
Messages
130
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
Estonia
Activity points
2,281
matlab line plot

y=x is linear equation

It is on a x axis

y=2x its going up

  • #6
Joined
Oct 22, 2005
Messages
296
Helped
27
Reputation
54
Reaction score
5
Trophy points
1,298
Location
South Africa
Activity points
3,462
plot line in matlab

I believe that the line(x,y) funtion in matlab can be overloaded to be used as a 3D function and thus be used as line(x,y,z). As stated the plot function will linearly interpolate but sometimes this is not desired. As an example animation using the line function will be more smooth than similar animations using the plot command. It all depends on what you want to do with the line.

Cheers
Slayer

  • #7
Joined
May 30, 2008
Messages
1
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,294
draw line in matlab

Here is a answer for ur Query......

just use the format

PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up.
PLOT(Y) plots the columns of Y versus their index.
If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).
In all other uses of PLOT, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
PLOT(X,Y,S) where S is a character string made from one element
from any or all the following 3 colunms:
y yellow . point - solid
m magenta o circle : dotted
c cyan x x-mark -. dashdot
r red + plus -- dashed
g green * star
b blue s square
w white d diamond
k black v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; PLOT(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
the (X,Y,S) triples, where the X's and Y's are vectors or matrices
and the S's are strings.
For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a
solid yellow line interpolating green circles at the data points.

  • #8

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
how to draw a line in matlab

aztroboy, here's a simple letter 'J'. You can expand it into more letters.

plot([5 5 4 3 2],[8 2 1 1 2],'k', [4 6],[8 8],'k'); xlim([0 10]); ylim([0 10]);

  • #9
Joined
Feb 29, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
Re: how to draw a line in matlab
aztroboy, here's a simple letter 'J'. You can expand it into more letters.

plot([5 5 4 3 2],[8 2 1 1 2],'k', [4 6],[8 8],'k'); xlim([0 10]); ylim([0 10]);


thanks a lot faztroboy

by your answer I did this

xlim([5 100]); ylim([5 100]); ------:arrow:----- Draw (x,y) axis

plot([5 5 4 3 2],[8 2 1 1 2],'k', [4 6],[8 8],'k'); xlim([0 10]); ylim([0 10]); --:arrow:-- Draw (J) letter --- k is ( black color of line )

plot([5 5 4 3 2],[8 2 1 1 2],'R', [4 6],[8 8],'R'); xlim([0 10]); ylim([0 10]);---:arrow:--- Draw (J) letter --- R is ( Red color of line )

plot([4 6],[8 8],'R'); xlim([0 10]); ylim([0 10]); --:arrow:---- Draw strait line ----- Red color

plot([2 9],[5 5],'K',[2 9],[4 4],'R'); xlim([0 10]); ylim([0 10]); --:arrow:------ Draw 2 straight lines ----- Red & black color

plot([4 8],[7 7],'K',[4 4],[3 7],'R',[4 8],[3 3],[8 8],[3 7],'R'); xlim([0 10]); ylim([0 10]); --:arrow:-- Draw square

Status
Not open for further replies.

Similar threads

  • Forums
  • EDA Theory
  • Elementary Electronic Questions
  • This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.

How to Draw a Line in a Plot Matlab

Source: https://www.edaboard.com/threads/matlab-how-to-draw-a-line-in-plot.39183/

0 Response to "How to Draw a Line in a Plot Matlab"

Enregistrer un commentaire

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel