how to vectorise this for loop?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
AKHILESH KESAVANUNNITHAN
el 14 de Ag. de 2018
Comentada: AKHILESH KESAVANUNNITHAN
el 14 de Ag. de 2018
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 comentarios
Jan
el 14 de Ag. de 2018
@AKHILESH KESAVANUNNITHAN: Please post a piece of code, which is running by copy&paste.
Respuestas (1)
OCDER
el 14 de Ag. de 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!
Ver también
Categorías
Más información sobre Language Fundamentals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!