how to vectorise this for loop?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 14 Ago 2018
@AKHILESH KESAVANUNNITHAN: Please post a piece of code, which is running by copy&paste.
Risposte (1)
OCDER
il 14 Ago 2018
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!
Vedere anche
Categorie
Scopri di più su Language Fundamentals in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!