Afficient way to create "sum matrix"
Mostrar comentarios más antiguos
Hi,
So i would like to implement a function that get a vector as input lets :
g=[g1, g2, g3]
and return a matrix that contain a sum of pairs: so for g , the output matrix G contain 9 elements the G(i,j)=g(i)+g(j)
The problem is that g will be very large vector.
Does anyone know an efficient way to do that with sparse matrices
Thanks
Respuesta aceptada
Más respuestas (1)
Orr Streicher
el 1 de Feb. de 2021
0 votos
2 comentarios
You could create a function, e.g.:
g = 1:3
f = @(r,c)sum(g([r,c]));
f(1,2)
Your question mentions sparse matrices: are most of the values in g zero?
Orr Streicher
el 1 de Feb. de 2021
Editada: Orr Streicher
el 1 de Feb. de 2021
Categorías
Más información sobre Sparse 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!