我有我的功能在下面,這個想法是,X是從循環中使用T的3x3提取,它正確地提取3行,但由於某種原因產生太多列,請參閱下面的示例。矩陣尺寸matlab
function T = tempsim(rows, cols, topNsideTemp, bottomTemp, tol)
T = zeros(rows,cols);
T(1,:) = topNsideTemp;
T(:,1) = topNsideTemp;
T(:,rows) = topNsideTemp;
T(rows,:) = bottomTemp;
S = [0 1 0; 1 1 1; 0 1 0];
X = zeros(3,3);
A = zeros(3,3);
for ii = 2:(cols-1);
jj = 2:(rows-1);
X = T([(ii-1) ii (ii+1)], [(jj-1) jj (jj+1)])
A = X.*S;
T = (sum(sum(A)))/5
end
試驗樣品
EDU>> T = tempsim(5,4,100,50,0)
X =
100 100 100 100 100 100 100 100 100
100 0 0 0 0 0 0 0 100
100 0 0 0 0 0 0 0 100
ans =
100 100 100 100 100 100 100 100 100
100 0 0 0 0 0 0 0 100
100 0 0 0 0 0 0 0 100
??? Error using ==> times
Matrix dimensions must agree.
Error in ==> tempsim at 14
A = X.*S;
就如何解決這一問題的任何想法?
工作,歡呼,你說得對我想在工作時不要改變T,最後輸出成品。 – Jordan
然後,在for循環之前加上'T2 = T;'並從'T2'而不是從'T'讀取'X'。或者檢查'conv2' ... –