我在Matlab中很新。我做了一個for循環與我到m,和j到n。我寫了這個代碼來獲取矩陣的一個子矩陣,但它一直給我這個錯誤如何更正「下標索引必須是真正的正整數或邏輯」。在我的代碼在Matlab中?
下標索引必須是真正的正整數或邏輯。 這是代碼
for i=1:m,
for j = 1:n,
display(i);
display(j);
edgeil = 2;
edgeib = 2;
edgejb = 2;
edgejl = 2;
if((i-CenteriSE)< 0)
edgeib = CenteriSE - (-1)*(i-CenteriSE);
end
if((i+ CenteriSE)> m)
temp = i+ CenteriSE - m;
edgeil = CenteriSE - temp;
end
if((j-CenterjSE)< 0)
edgejb = CenterjSE- (-1)*(j-CenterjSE);
end
if((j+ CenterjSE)> n)
temp2 = j+ CenterjSE - n;
edgejl = CenterjSE - temp2;
end
bok1 = round(edgeib);
bok2 = round(edgeil);
bok3 = round(edgejb);
bok4 = round(edgejl);
display(bok1);
display(bok2);
if((bok1 == round(bok1)) && (bok2 == round(bok2)) && (bok3 == round(bok3)) && (bok4 == round(bok4)))
B = circles(i-round(bok1):i+round(bok2),j-round(bok3):j+round(bok4));
end
我寫的if語句和輪s到糾正它,但它不工作。請幫我解決這個問題?
CenteriSE和CenterjSE都是2.它不會超出範圍。 – Ada 2011-03-05 21:33:26
我也使用abs(..),但我不知道爲什麼id一直給我這個錯誤。請幫助一下? – Ada 2011-03-05 21:39:15
它說什麼線?你有沒有試過圓圈(round(i-bok1):round(i + bok2),round(j-bok3):round(j + bok4));'? (這裏可能有一個off-by-one ......) – rlibby 2011-03-05 22:01:49