Search code examples
matlabplothorizontal-line

Matlab horizontal line plot with arrow


I am trying to plot a graph with horizontal lines with arrows on the end of the line to show continuity in Matlab. How is this possible?

Picture for reference: https://i.sstatic.net/IYCh3.jpg


Solution

  • p1 = [2 3];                         % First Point
    p2 = [9 3];                         % Second Point
    dp = p2-p1;                         % Difference
    figure(1)
    quiver(p1(1),p1(2),dp(1),dp(2),0)
    grid
    axis([0  10    0  10])
    text(p1(1),p1(2), sprintf('(%.0f,%.0f)',p1))
    text(p2(1),p2(2), sprintf('(%.0f,%.0f)',p2))
    

    You can even remove the grid commando and text commando to get a white background for your figure :

    p1 = [2 3];                         % First Point
    p2 = [9 3];                         % Second Point
    dp = p2-p1;                         % Difference
    figure(1)
    quiver(p1(1),p1(2),dp(1),dp(2))
    axis([0  10    0  10])