How to connect two points with a line

893 Ansichten (letzte 30 Tage)
Yuang
Yuang am 24 Sep. 2014
Kommentiert: Sindhuja john am 26 Mai 2023
I want to plot a line between two know points in coordinate.
Like I have two points (1,2) and (3,4). I want to connect them with a line segment.
I try line([2,3],[3,4]) and plot([1,2],[3,4]). Both are set x and y limits not connect them.
Can anyone help?
Thank you
  2 Kommentare
k khaja
k khaja am 10 Mär. 2022
Bearbeitet: k khaja am 10 Mär. 2022
How can we add weight to edge after ploting the above line.
Thanks in advance
Star Strider
Star Strider am 10 Mär. 2022
How can we add weight to edge after ploting the above line.
Not sure what that means. Try the 'LineWidth' property to create a thicker line.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 24 Sep. 2014
You need to plot the x-values in one vector and the y-values in another vector:
plot([1 3], [2 4])
The x-values in your two points are [1 3] and the y-values are [2 4].

Weitere Antworten (1)

Thomas Merlo
Thomas Merlo am 2 Mai 2018
put each point in an [x y] vector: p1 = [1 2], p2 = [3 4]. Then plot plot([ p1(1) p2(1)], [p1(2) p2(2)]);

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by