Azzera filtri
Azzera filtri

How can I a void this nested loop?

1 visualizzazione (ultimi 30 giorni)
Nona HH
Nona HH il 30 Dic 2017
Commentato: Nona HH il 1 Gen 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.

Risposte (1)

Roger Stafford
Roger Stafford il 30 Dic 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by