Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Removing the section of line after you have plotted it is difficult. You can see that the line is made up of one MATLAB object by the following code:</p> <pre><code>x = 1:10; y = 1:10; H = plot(x, y, '-o'); get(H, 'children') </code></pre> <p>ans =</p> <p>Empty matrix: 0-by-1</p> <p>We can see that the line has no children, so there are no 'subparts' that we can remove. However, there are some cheeky tricks we can use to try to achieve the same effect.</p> <hr> <p><strong>Plot two lines separately</strong></p> <p>...using <code>hold on</code>. See Victor Hugo's answer. This is the proper way of achieving our goal.</p> <hr> <p><strong>Plot two separate lines in one</strong></p> <p>MATLAB doesn'y plot points with a NaN value. By modifying the input vectors, you can make MATLAB skip a point to give the effect of a broken line:</p> <pre><code>x = [0 1 2 2 3 4 5 6 7 8 9]; y = [0 1 2 nan 3 4 5 6 7 8 9]; plot(x, y, '-o'); </code></pre> <p>This is equivalent to plotting a line from [0, 0] to [2, 2], skipping the next point, then starting again at [3, 3] and continuing to [9, 9].</p> <p><img src="https://i.stack.imgur.com/s5nPN.png" alt="enter image description here"></p> <hr> <p><strong>'Erase' part of the line</strong></p> <p>This is the nastiest way of doing it, but is a cheap hack that could work if you can't be bothered with changing your input arrays. First plot the line:</p> <pre><code>x = 1:10; y = 1:10; plot(x, y, '-o'); </code></pre> <p><img src="https://i.stack.imgur.com/zyKyn.png" alt="enter image description here"></p> <p>Now plot a white line over the part you wish to erase:</p> <pre><code>hold on plot([2 3], [2 3], 'w'); </code></pre> <p><img src="https://i.stack.imgur.com/xHSGY.png" alt="enter image description here"></p> <p>As you can see, the result doesn't quite look right, and will respond badly if you try to do other things to the graph. In short, I wouldn't recommend this method but it might come in useful in desperate times!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload