Borrar filtros
Borrar filtros

How to vectorize the following code?

3 visualizaciones (últimos 30 días)
pietro
pietro el 1 de Jun. de 2014
Respondida: dpb el 1 de Jun. de 2014
Hi all,
How can I vectorize the following code?
a=struct('cycles',[])
a(1).cycles=[rand(15,20];
a(2).cycles=[rand(15,20];
a(3).cycles=[rand(15,20];
for i=1:length(a)
totalnum(i)=sum(a(i).cycles)
end
Where totalnum should be a [3,20] array.
Thanks
cheers
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 1 de Jun. de 2014
What is a?
pietro
pietro el 1 de Jun. de 2014
You're on right, I have just edited the question. thanks

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 1 de Jun. de 2014
reshape(sum([a.cycles]),length(a),[]).'

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by