Is there a more efficient method for this matrix calculation?
Mostrar comentarios más antiguos
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
Respuestas (1)
Image Analyst
el 29 de Mzo. de 2014
Use conv2():
kernel = 0.25 * [0, 1, 0; 1, 0, 1; 0, 1, 0];
H1 = conv2(HOLD, kernel, 'same');
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!