Effacer les filtres
Effacer les filtres

How can I a void this nested loop?

1 vue (au cours des 30 derniers jours)
Nona HH
Nona HH le 30 Déc 2017
Commenté : Nona HH le 1 Jan 2018
How could I vectorize this nested loop?
M1=[4 5 6; 9 8 7];
P= [2 3 4; 1 2 3];
for k=1 : 2
for j=1 : 3
pn(k,j)= normrnd(M1(k,j), (max(P(:,j)) - min(P(:,j))) );
end
end
I need to use the normrnd function for each element in the M1 matrix that's why I do it by this way. If I could avoid this loop I can save the time. Any help will be appreciated.
Thanks in advance.

Réponses (1)

Roger Stafford
Roger Stafford le 30 Déc 2017
pn = normrnd(M1,repmat(max(P,[],1)-min(P,[],1),2,1));
I'm inclined to doubt that this will save you any significant amount of execution time, however.
  1 commentaire
Nona HH
Nona HH le 1 Jan 2018
Thank you so much for your reply.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by