How to plot vertical line in octave?

Austin A picture Austin A · Sep 7, 2014 · Viewed 16.9k times · Source

What it the best way to plot a vertical line using Octave?

Answer

Austin A picture Austin A · Sep 7, 2014

So, I have two methods for this. One, I found, and the other I made up.

Method 1: From here.

%% Set x value where verticle line should intersect the x-axis.
x = 0;
%% plot a line between two points using plot([x1,x2],[y1,y2])
plot([x,x],[-10,10]);

Method 2: A slightly different approach, exact same result

%% Setup a vector of x values
x = linspace(0,0,100);
%% Setup a vector of y values
y = linspace(0,10,100);
%% Plot the paired points in a line
plot(x,y);

I think Method 2 may write more information to memory before the plot process and it's a line longer, so in my eyes, Method 1 should be the better option. If you prefer Method 2, make sure your x and y vectors are the same dimension or you'll end up with a bunch of dots where you're line should be.