Drawing line segments
Bill Denney
bill at denney.ws
Tue Jun 17 17:08:35 CDT 2008
Shaun Jackman wrote:
> I want to draw a number of scattered line segments in a plot. I have a matrix
> with four columns: [x0 y0 x1 y1]. Is there a better/faster approach than
> calling `line' in a for loop? I'd rather format the data in a way that I can
> draw the scattered line-segment plot with a single call to either plot or line.
> If it makes any difference, in this particular case all my lines are
> horizontal, so y0 == y1, for any given line segment.
Hi Shaun,
If you do
plot ([1;2;nan;4;5], [1;2;nan;4;5])
you get broken lines where the nan values are. For your problem, you
could do something like (assuming that data is your 4 column matrix):
x = reshape ([data(:,1:2) nan(rows(data),1)]', [], 1);
y = reshape ([data(:,3:4) nan(rows(data),1)]', [], 1);
plot (x,y)
Have a good day,
Bill
More information about the Help-octave
mailing list