Summing matrices without loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Esegboria Osarhemen
el 3 de Mzo. de 2019
Comentada: Esegboria Osarhemen
el 4 de Mzo. de 2019
I have a this function
function mat(i)
which generates an nxn matrix for a value of i. There are 10000 possible values of i, hence 10000 possible nxn matrices. I want to use mat(i) in another function and sum the 10000 possible matrices. How can i do this without a loop?
0 comentarios
Respuesta aceptada
Walter Roberson
el 3 de Mzo. de 2019
all_mat = arrayfun(@mat, 1:10000, 'uniform', 0);
total = sum( cat(3,all_mat{:}), 3 );
This still uses a loop: it is just a hidden loop. It is probably less efficient than using a loop.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!