Borrar filtros
Borrar filtros

Speed up for loops for arrays

1 visualización (últimos 30 días)
Mantas Vaitonis
Mantas Vaitonis el 9 de Nov. de 2018
Editada: madhan ravi el 9 de Nov. de 2018
Hello, Maybe someone could help me to speedup this type of for loop? I did try parfor, I did try to think of way using GPU, but it does not work with indexing.
clear;
a=7811200001;
d=1083355908;
c=zeros(1083355908,1)
parfor i = 1:d
c(i,1)=a+i;
end

Respuesta aceptada

madhan ravi
madhan ravi el 9 de Nov. de 2018
Editada: madhan ravi el 9 de Nov. de 2018
a=7811200001;
d=1083355908;
c=a+(1:d);
c=(a+1):(a+d); %edited after jan's comment
  10 comentarios
Jan
Jan el 9 de Nov. de 2018
Another hint: In a+(1:d) you create the double vector 1:d at first and then add a to each element. It is more efficient to omit the addition and create vector directly:
(a+1):(a+d)
madhan ravi
madhan ravi el 9 de Nov. de 2018
Editada: madhan ravi el 9 de Nov. de 2018
Selbverständlich , danke schön @Jan

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by