help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing line segments


From: Bill Denney
Subject: Re: Drawing line segments
Date: Tue, 17 Jun 2008 18:08:35 -0400
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]