title: Strange Matlab error: "??? Subscript indices must either be real positive integers or logicals"
body: <p>I have a function <code>func</code> that returns a vector <code>a</code>. I usually plot a and then perform further analysis on it. I have a certain scenario when once I try to plot a, I get a "<code>??? Subscript indices must either be real positive integers or logicals</code>" error. Take a look at the following piece of code to see the vector's behavior:</p>
  
  <pre><code>K&gt;&gt; a
  
  a =
      5.7047    6.3529    6.4826    5.5750    4.1488    5.8343    5.3157    5.4454    
  
  K&gt;&gt; plot(a)
  ??? Subscript indices must either be real positive integers or logicals.
  
  K&gt;&gt; for i=1:length(a); b(i) = a(i); end;
  K&gt;&gt; b
  
  b =
      5.7047    6.3529    6.4826    5.5750    4.1488    5.8343    5.3157    5.4454    
  
  K&gt;&gt; plot(b)
  ??? Subscript indices must either be real positive integers or logicals.
  </code></pre>
  
  <p>The scenario where this happens is when I call function <code>func</code> from within another function (call it <code>outer_func</code>), and return the result directly as <code>outer_func</code>'s result. When debugging inside <code>outer_func</code>, I can plot a properly, but outside the scope of <code>outer_func</code>, its result has the above behavior.</p>
  
  <p>What can cause this? Where do I start from?</p>