title: Summation with conditions in for loop
body: <p>I need to calculate the following in MATLAB:</p>
  
  <p><img src="https://i.stack.imgur.com/bdl0w.gif" alt="\tau = \sum_{i=1}^n \sum_{j \neq i} \sum_{k \neq i,j} w_{ji}*w_{ki}*d_j*d_k"></p>
  
  <p>Basically, it is a sum over a matrix but you do not include the instances where i=j and k = i or j.
  I have coded this as follows:</p>
  
  <pre><code>for l=2:1001;
  tau1(1) = 0;
  for i = 1:34
      for j = 1:34
          for k = 1:34
              if j ~= i &amp; k ~= i &amp; k ~= j
                  tau1(l) = tau1(l-1) + TecCoef1(j,i)*TecCoef1(k,i)*herf1(j)*herf1(k);
              else
                  tau1(l) = tau1(l-1);
              end
          end
      end
  end
  end
  </code></pre>
  
  <p>The code itself is fine. However, I need to calculate this for 1000 iterations. And this is where I am having issues. I simply get 1000 zeros, most likely due to the fact that I initialised tau(1) as 0. Any suggestions?</p>