title: "Subscript indices must either be real positive integers or logicals"
body: <p>I am aware that dozens of threads have been started about this particular error, but none of them actually answer the problem I'm having.</p>
  
  <p>I'm trying to generate a plot of voltage spikes at given intervals using the following code:</p>
  
  <pre><code>    V=zeros(1:NN);
  
      nspace=50;            % Spacing of the spikes in angstroms
      V0=-0.1*eV2J;         % magnitude of the voltage spikes
  
      for n=10/nspace:NN:nspace
          V(nspace*n)=V0;
      end
  </code></pre>
  
  <p>The variables NN and eV2J are already defined earlier in the code.</p>
  
  <p>Now, here's the problem I'm having that the other threads don't answer.  The indexing error only pops up for certain values of nspace, but not for others.  For example, this block of code executes just fine for...</p>
  
  <pre><code>nspace = 20,23,24,27,29,31,32,33,34,36,37,38,40
  </code></pre>
  
  <p>...but the error occurs for all other integer values between 20 and 40, and this seemingly random distribution of acceptable values continues on past 40 as well.  The index generated for all of these values are indeed integers (starting at 10 and incrementing by nspace each loop).</p>
  
  <p>Every thread I've seen for this error states that is occurs when a variable sharaes a name with a built in MATLAB function, or when the index is not a positive real integer or logical.  That is clearly not the case here.</p>
  
  <p>Any ideas?</p>