Vectorization of an arrayfun problem
Mostrar comentarios más antiguos
Consider a AxB matrix M with A>1 & B>1. I need to perform the following operation:
Output=arrayfun(@(input) sum(p_matrix.*max(input,M),'all'), M);
For each 1x1 entry of M (input), max(input,M) returns a AxB matrix with the greatest numbers between "input" and each entry of M, element-wise. The result is multiplied by AxB p_matrix, element-wise, and its elements are summed up. The result is saved in the corresponding entry of Output, a AxB matrix as well.
Arrayfun slowly loops over each element of M, one by one. Is there any way to build a vectorized version of this command?
Thanks sincerely.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices 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!