K=100;
a=zeros(K,1);
for u = 0:K-1
for b = 0:K-1
a(u+1) = a(u+1) + s(b+1)*exp((-2j*pi*u*b/K));
end
end

2 comentarios

Matt J
Matt J el 21 de En. de 2018
What is "k" in s(k+1)? DO you mean s(b+1)?
Miguel Reina
Miguel Reina el 22 de En. de 2018
Yes is b+1

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 21 de En. de 2018

1 voto

Well you could try meshgrid() but I think it might make it a little more confusing to understand what it's doing. With only 100x100 array to fill, a double for loop will be very fast so even if you did vectorize it, don't expect to notice any speed difference.
Matt J
Matt J el 22 de En. de 2018

0 votos

A less efficient way,
z=0:K;
a=exp((-2j*pi/K)*z.'*z)*s(:);

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de En. de 2018

Respondida:

el 22 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by