Vectorize a doble loop for
Afficher commentaires plus anciens
Hi everyboy
I am trying to vectorize the following code, but I can't. I want to calculate the matrix p_hat from the matrixs p and omega (these last matrix are of the same order) . The vector a is a function that gives me another index.
Could anyone help me, please?
for k=1:length(a)
for j=1:length(a)
if omega(j,k)==1
p_hat(k,a(j))=p(j,k);
end
end
end
2 commentaires
Stephen23
le 2 Juin 2018
" The vector a is a function that gives me another index"
It can't be both: is it a vector, or a function?
jose ramirez alvarez
le 2 Juin 2018
Réponse acceptée
Plus de réponses (1)
Bruno Luong
le 2 Juin 2018
Modifié(e) : Bruno Luong
le 2 Juin 2018
p = rand(3,4)
a = ceil(10*rand(size(p,1),1))
omega = rand(size(p))>0.4
[j,k] = find(omega)
p_hat = accumarray([k,a(j)],p(omega))
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!