title: MATLAB - having trouble with sub-array
body: <p>I am trying to sub-array in MATLAB with no luck.</p>
  
  <p>This is what I am doing:</p>
  
  <pre><code>a = randint(latticeSize, 1, [0 1]);
  
  % a 1st attempt which works but sucks 
  localPattern = [a(i-1) a(i) a(i+1)];
  </code></pre>
  
  <p>The above works fine but I want to generalize it with something like:</p>
  
  <pre><code>% this is how I'd like to do it as more general
  localPattern = a(i-1 : i+1);
  </code></pre>
  
  <p><strong>Is there any difference between the two?</strong> A display shows the same result but if I use the different alternatives in my code I get very different results (I get what I want with the 1st one).</p>
  
  <p>In case the rest of the code is needed I can provide it, but if someone can spot something just looking at the above then there's no need. </p>