필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by