开发者

sum(Array) says index exceeds matrix dimensions [duplicate]

开发者 https://www.devze.com 2023-01-20 17:13 出处:网络
This question already has answers here: Why am I getting the error "Index exceeds matrix dimensions"?
This question already has answers here: Why am I getting the error "Index exceeds matrix dimensions"? (2 answers) Closed 3 years ago.

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开发者_C百科 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 :-

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消