フィルターのクリア

How can I a void this nested loop?

1 回表示 (過去 30 日間)
Nona HH
Nona HH 2017 年 12 月 30 日
コメント済み: Nona HH 2018 年 1 月 1 日
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.

回答 (1 件)

Roger Stafford
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.
  1 件のコメント
Nona HH
Nona HH 2018 年 1 月 1 日
Thank you so much for your reply.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by