I can plot multiple disconnected line segments in MATLAB using:

```
x1=[0 1 .2];
y1=[0 2 1];
x2=[1 .5 .8];
y2=[1 -1 -.5];
lh=line([ x1' x2' ]',[ y1' y2' ]');

```

[![Plotting multiple line segments in MATLAB](https://i.stack.imgur.com/uXGYl.jpg)](https://i.stack.imgur.com/uXGYl.jpg)

Here `x1` and `y1` are the arrays of the x- and y-coordinates of the start points, and `x2` and `y2` of the end points.

`lh` is the handler of the multiple line object created:

[![Multiple line object](https://i.stack.imgur.com/6PLyX.jpg)](https://i.stack.imgur.com/6PLyX.jpg)

However, I cannot modify the data of this object using the traditional `set` as for a single line:

```
>> set(lh, 'XData', [ x1' x2' ]');
Error using matlab.graphics.primitive.Line/set
While setting the 'XData' property of Line:
Value must be a vector of numeric type

```

Any ideas how to do this?

Additional info: querying its XData yields:

```
>> lh.XData

ans =

     0     1

ans =

    1.0000    0.5000

ans =

    0.2000    0.8000

```