title: Matlab matrix operations without loops
body: <p>I have an issue with a code performing some array operations. It is getting too slow, because I am using loops. I am trying for some time to optimize this code and to re-write it with less or without loops. Until now unsuccessfully. Can you please help me solve this:</p>
  
  <pre><code>YVal = 1:1:100000;
  M_MAX = 1000;
  N_MAX = 2000;
  clear YTemp
  tic
  for M=1:1:M_MAX 
      for N = 1:1:N_MAX 
         YTemp(M,N) = sum(YVal (N+1:N+M)  ) - sum(YVal   (1:M)  );  
      end
  end
  </code></pre>
  
  <p>For large <code>N_MAX</code> and <code>M_MAX</code> the execution time of these two loops is very high. How can I optimize this?</p>
  
  <p>Thank you!</p>