Vectorizing Calculation of the Autocorreltion function of a Matrix (Per Column)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Royi Avital
el 27 de Jul. de 2011
Respondida: Royi Avital
el 11 de Sept. de 2014
Hello.
I have a matrix
A = [1 2 3; 4 5 6; 7 8 9];
I want to calculate the Autocorrelation function of each of its columns.
Simple way to do so:
for ii = 1:size(A, 2)
autocorrelationFunction(:, ii) = conv2(A(:, ii), A(end:-1:1, ii));
end
Could anyone think of a vectorized way of doing so?
Thanks.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Daniel Shub
el 27 de Jul. de 2011
Wow, it is like a vectorization party in here today. Why do you want to vectorize your code? In recent years MATLAB has substantially sped up loops. If you are not using r2011a, you could speed up your loop by initializing autorcorrelationFunction to the correct size (r2011a has supposedly cut down on the cost of not pre-allocating arrays). You might be able to get a speed increase out of vectorization, but it may not be as big as you expect.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!