??? Attempted to access cmtx(1.00024,1); index must be a positive integer or logical.
1 回表示 (過去 30 日間)
古いコメントを表示
hello sir, I am working with a image . and i am applying entropic thresholding on the image ,and i get the error. how to solve this error
"??? Attempted to access cmtx(1.00024,1); index must be a positive integer or logical."
Error in ==> file1>GABOR_Callback at 809
cmtx(fix(rt(m,n))+1,fix(rt(m,n+1))+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1
here rt is my image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153186/image.jpeg)
and my thresholding code is
[M,N] =size(rt);
cmtx = zeros(256,256);
for m = 1:M-1
for n = 1:N-1
cmtx(rt(m,n)+1,rt(m,n+1)+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1;
end
end
scmtx = sum(cmtx(:)); prob = cmtx/scmtx;
emax = -100; for i=1:255
probA = 0;
probC = 0;
subProbA = prob(1:i,1:i);
probA = sum(subProbA(:));
HA(i) = -0.5*(probA*log2(probA+0.0000001));
subProbC = prob(i+1:256,i+1:256);
probC = sum(subProbC(:));
HC(i) = -0.5*(probC*log2(probC+0.0000001));
e1(i) = HA(i) + HC(i);
if e1(i) >= emax
emax = e1(i);
tt1 = i;
end
end
end
0 件のコメント
採用された回答
David Sanchez
2013 年 11 月 22 日
your sentece:
cmtx(fix(rt(m,n))+1,fix(rt(m,n+1))+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1
returns a value for
rt(m,n)+1 = 1.00024
you can only access integer values when dealing with matrices. Try to round the values of both rt(m,n)+1 and rt(m+1,n+1)+1 or modify your rt function in order to avoid decimals:
round(rt(m,n)+1) = 1
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!