Hello,
i have the following for loop and i am trying to find a way to avoid the loops and reduce the time. is it possible to calculate A and B without using a for loop ?
for i = 1:m
for j = 1:m
A(i,j) = A(i,j)/(sqrt(Dn(i,i)*Dn(j,j)));
end
end
for i = 1:m
for j=1:n
B(i,j) = B(i,j)/(sqrt(Dn(i,i)*Dn(j+m,j+m)));
end
end
A is an mxm matrix
B is an mxn matrix
and Dn is an NxN diagonal matrix
with N = 247 , n = N-m = 217 and m =30.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Mayo de 2019

0 votos

sdnd = sqrt(diag(Dn)); %gives a column vector
A = A ./ (sdnd(1:m) .* sdnd(1:m).');
B = B ./ (sdnd(1:m) .* sdnd(m+1:end).');
Requires R2016b or later.

Más respuestas (0)

Categorías

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

Productos

Versión

R2018a

Preguntada:

el 5 de Mayo de 2019

Comentada:

el 6 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by