title: How to ignore values that are negative when plotting a line plot with matlab?
body: <p>I have a matrix where some values have <code>-1</code> as an indication that there was an error. Normally I would just use <code>ylim([0 100])</code> to not show these values in my graph, but when using line graph the connection will still drop down to the point. I want a chart that consists of lines, not a scatter plot. Is there a simple way of ignoring negative values when plotting a line and only connect positive values when using the plot function in MATLAB?</p>
  
  <p>I have written a small example program which behaves similarly, but the way I use seems a little "too complicated" and I want to know if there is an easier way to achieve this. It works fine as I put the values to <code>NaN</code>, and now the <code>x</code> and <code>y</code> values are the same amount. However deleting or sorting out the values from the vector will lead to different amount of <code>x</code> and <code>y</code> values. </p>
  
  <p>I was hoping for a modification or a flag or something.</p>
  
  <pre><code>x = 2*rand(10) - rand(10)
  xx = 10:10:100;
  
  figure;
  for i=1:length(x)
      for j=1:length(x(i,:))
          if x(i,j) &lt; 0
             x(i,j) = NaN; 
          end
      end
  end
  
  plot(xx,x)
  </code></pre>
  
  <p>Please note that this is only an example, the whole code would be too large to post here. </p>
  
  <p>When having non-corresponding <code>x</code>-values (so that the plot function simply uses <code>1,2,3...</code> and so on for the corresponding <code>y</code> values) this can be achieved by using </p>
  
  <pre><code>plot(x(x&gt;0))
  </code></pre>
  
  <p>In this case, the corresponding values are different, in the real code they are measured data, here I simply use a 10th step for simplification. </p>
  
  <pre><code>x = 2*rand(10) - rand(10)
  xx = 10:10:100;
  
  plot(xx,x(x&gt;0))
  </code></pre>
  
  <p>The above code will error with the message "Vectors must be the same length".</p>