How can I a void this nested loop?
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
Roger Stafford
2017 年 12 月 30 日
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.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!