sum(Array) says index exceeds matrix dimensions [duplicate]
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;
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.
The only way you can get such a bug is if you have declared a variable sum
somewhere.
Run clear sum
(or clear all
, or restart Matlab) and try again, then everything should work fine.
精彩评论