title: using tic toc function in matlab
body: <p>I have these two different ways to implement the same thing but I guess the second is the best. However, I get a better result when using tic toc for the first. How comes ?</p>
  
  <pre><code>j=6;
  i=j;
  Savings = zeros(i,j);
  Costs = magic(400);
  
  tic;
  for x=2:i
     for y=2:j
       if(x ~= y)
         Savings(x,y) = Costs(x,1) + Costs(1,y) - Costs(x,y);
       end
     end
  end
  first=toc;
  
  disp(num2str(first))
  
  Savings = zeros(i,j);
  
  tic;
  Ix=2:i; 
  Iy=2:j;
  I = false(i,j);
  I(Ix,Iy) = bsxfun(@ne, Ix', Iy);
  S = bsxfun(@plus, Costs(Ix,1), Costs(1,Iy)) - Costs(Ix,Iy);
  Savings(I) = S(I(Ix,Iy));
  second=toc;
  
  temp = Savings;
  disp(num2str(second))
  </code></pre>