how to vectorise this for loop?
3 ビュー (過去 30 日間)
古いコメントを表示
for i = 2:numHarm
h1HatN = h1HatN + alpha(i-1)*sin(i*2*pi*Jint*n/M) + beta(i-1)*cos(i*2*pi*Jint*n/M);
h1Hat2N = h1Hat2N + alpha(i-1)*sin(i*2*pi*Jnew2*n/M) + beta(i-1)*cos(i*2*pi*Jnew2*n/M);
end
5 件のコメント
Jan
2018 年 8 月 14 日
@AKHILESH KESAVANUNNITHAN: Please post a piece of code, which is running by copy&paste.
回答 (1 件)
OCDER
2018 年 8 月 14 日
Jint = 263;
Jnew2 = 360;
z = 262144;
numHarm = 400;
n = rand(z, 1);
M = rand(z, 1);
alpha = rand(1, numHarm);
beta = rand(1, numHarm);
h1HatN = rand(z, 1);
h1Hat2N = rand(z, 1);
i = [2:numHarm];
h1HatN = h1HatN + sum(alpha(i-1).*sin(i*2*pi*Jint.*n./M) + beta(i-1).*cos(i*2*pi*Jint.*n./M), 2);
h1Hat2N = h1Hat2N + sum(alpha(i-1).*sin(i*2*pi*Jnew2.*n./M) + beta(i-1).*cos(i*2*pi*Jnew2.*n./M), 2);
%check this n/M vs n./M . n/M for 262144x1 / 262144x1 matrix will generate a 512 GB matrix!
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!