help-octave
[Top][All Lists]

## Re: Plot a line passing through two points to the axis

 From: Mike Miller Subject: Re: Plot a line passing through two points to the axis Date: Thu, 3 Oct 2013 23:43:13 -0400

```On Thu, Oct 3, 2013 at 17:12:16 -0700, Victor Semanic wrote:
> Hello: I am plotting a line in Octave by having the line run through two
> points.
> Here are the commands:
>
> octave:3> axis([-1,1,-1,1])
> octave:4> hold on
> octave:5> plot(2*rand(1,2)-1, 2*rand(1,2)-1)
>
> The line plots fine.  However, I want to extend the line such that it touches
> the x and y axes.  When the points in the plot() command are nearby
> each other, the line is short.  What I want to do is to extend the line such
> that it touches the axes.
>
> Can anyone suggest how to do this?  I would appreciate it very much.

So you want to extrapolate a line through your two endpoints.
Something like this?

x = 2 * rand (1, 2) - 1;
y = 2 * rand (1, 2) - 1;
xi = [-1 1];
yi = interp1 (x, y, xi, "extrap");
plot (xi, yi);

HTH,

--
mike

```