title: How can I check if a MATLAB handle is valid?
body: <p>I manipulate data on a plot using its handle:</p>
  
  <pre><code>x = 1:10; y = sin(x);
  h1 = line(x,y);
  </code></pre>
  
  <p>However, if the figure gets closed before the script actually terminates, doing something like this returns an error. </p>
  
  <pre><code>&gt;&gt;set(h1,'Color','green') % line is green
  ??? Error using ==&gt; set
  Invalid handle object.
  </code></pre>
  
  <p>Is there a way to check if <code>h1</code> is a valid handle before doing any manipulations with it?</p>