title: sum(Array) says index exceeds matrix dimensions
body: <p><br>
  I am a newbie to Matlab .I was trying to do some image matching.Image X is bigger and Image Y is smaller.Our aim is to find all possible overlaps of y with x and then compute sum of square differences for RGB at each such overlap(ie x^2+y^2+z^2).So I  find a location (i,j) in bigger image from where we pick a tile and match .
  To be precise here is the code :-</p>
  
  <pre><code>a=size(X,1)-size(Y,1);
  b=size(X,2)-size(Y,2);
  Z=ones(a,b);
  
  for i=1:a
  for j=1:b 
      A=[X(i:i+size(Y,1)-1,j:j+size(Y,2)-1,1)-Y(1:end,1:end,1)].^2;
      B=[X(i:i+size(Y,1)-1,j:j+size(Y,2)-1,2)-Y(1:end,1:end,2)].^2;
      C=[X(i:i+size(Y,1)-1,j:j+size(Y,2)-1,3)-Y(1:end,1:end,3)].^2;           
      T=A+B+C
      size(T)
      P=sum(sum(T))
      %Z(i,j)=sum(sum(T));
  end;    
  end;    
  </code></pre>
  
  <p>Now the problem is the line sum(sum(T)) throws up an error-'Index exceeds Matrix Dimensions'.Can someone help?My aim is to add all these differences and put it in a matrix Z.</p>