Is there a more efficient method for this matrix calculation?
显示 更早的评论
Is this the most efficient way to do a calculation on a subset of terms in a matrix? For instance if I have a 23x23 matrix and wanted to replace columns 2 through 22 in rows 2 through 22 by the average of the four adjacent terms? This method seems to recalculate the entire matrix at every step rather than just the individual term.
for i=2:22
for j=2:22
H1(i,j)=0.25*(HOLD(i,j+1)+HOLD(i,j-1)+HOLD(i+1,j)+HOLD(i-1,j));
end
end
回答(1 个)
Image Analyst
2014-3-29
Use conv2():
kernel = 0.25 * [0, 1, 0; 1, 0, 1; 0, 1, 0];
H1 = conv2(HOLD, kernel, 'same');
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!