title: Create overlapping and non-overlapping sliding windows in MATLAB
body: <p>I am trying to create overlapping and non-overlapping blocks of data from an array <code>Data</code> containing<code>N</code> elements. How can I correctly form sub-arrays of <code>Data</code> for any <code>N</code> and any <code>blksze</code>? The following code is for non-overlapping blocks throws error because of the number of elements exceed when creating sub-blocks. For example, let <code>Data = [1,2,3,4,5,6]</code>, then </p>
  
  <ul>
  <li><p>for overlapping case I should get : block size <code>blksze = 2</code>, I would get <code>block1 = [1,2], block2 = [2,3], block3 = [3,4], block4 = [4,5], block5 = [5,6]</code> </p></li>
  <li><p>for non-overlapping :  block size <code>blksze = 2</code>, I would get <code>block1 = [1,2], block2 = [3,4], block3 = [5,6]</code></p></li>
  </ul>
  
  <h1>Code snippet</h1>
  
  <pre><code>N= 100;
  n = 4;
  Data = randi([1 n],1,N);
  blksze = 10;
  Nblocks = N / blksze;
  counter = 1;
  for i = 1 : Nblocks
      block{i} = Data(counter : counter + blksze - 1);
      counter = blksze + 1;
  end
  </code></pre>