Vectorize a doble loop for
Mostra commenti meno recenti
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 Commenti
Stephen23
il 2 Giu 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
il 2 Giu 2018
Risposta accettata
Più risposte (1)
Bruno Luong
il 2 Giu 2018
Modificato: Bruno Luong
il 2 Giu 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))
Categorie
Scopri di più su Multirate Signal Processing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!