title: Inserting small vectors into a larger one
body: <p>Let's say we have a "Dirac comb" which gives the beginning positions of some "pattern":</p>
  
  <pre><code>N_pattern = 5; pattern = rand(1,N_pattern); 
  N = 100;  dirac_comb =  zeros(1, N);  
  idx = [1 20 50 80];           % let's say we want four occurrences of the pattern inside the final_vector
  dirac_comb (idx) = 1;         % let's say this the comb with the positions of patterns
  </code></pre>
  
  <p>All I want to do is to insert the "pattern" vector on the positions indicated by the Dirac comb. Normally, this may be done by a convolution:</p>
  
  <pre><code>final_vector = conv(dirac_comb, pattern);
  </code></pre>
  
  <p>I don't want to use the convolution because I use very large vectors and thus it is very slow. The presence of the Dirac comb in this problem is a little bit forced, the <code>idx</code> variable might be enough to solve this problem.</p>
  
  <p><strong>First question:</strong> how to insert the "pattern" in the <code>final_vect</code> at the positions indicated by <code>idx</code>, in a vectorized way.   </p>
  
  <p><strong>Second question:</strong> let's say we randomized the positions <code>idx</code> of the patterns, so there is a possibility that two patterns may intersect. If this would happen, I have to sum up these two patterns (the region of intersection).              </p>
  
  <pre><code>idx = randi([1 N-N_pattern],[1, 8]); % lets' say we have 8 occurrences
  </code></pre>
  
  <p>Should it be possible to take into account this summation, yet in a vectorized manner?</p>