필터 지우기
필터 지우기

how can i vectorize this loop?

조회 수: 1 (최근 30일)
Miguel Reina
Miguel Reina 2018년 1월 21일
답변: Matt J 2018년 1월 22일
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
Matt J
Matt J 2018년 1월 21일
What is "k" in s(k+1)? DO you mean s(b+1)?
Miguel Reina
Miguel Reina 2018년 1월 22일
Yes is b+1

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2018년 1월 21일

추가 답변 (2개)

Image Analyst
Image Analyst 2018년 1월 21일
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 2018년 1월 22일
A less efficient way,
z=0:K;
a=exp((-2j*pi/K)*z.'*z)*s(:);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by