필터 지우기
필터 지우기

How can I remove for loops?

조회 수: 2 (최근 30일)
Griselda
Griselda 2013년 10월 25일
댓글: Griselda 2013년 10월 25일
Hello. I would like to remove the for loops from this script. Could anyone provide me information on how to do it? The loop takes a long time to run. Thank you!
n=12000;
resamples=5000;
Z=zeros(1,5);
Y=zeros(resamples,5);
for j=1:resamples
for k=1:n
r=randi(n);
Z=Z+B(r,:);
end
Y(j,:)=Z;
end
  댓글 수: 1
Matt J
Matt J 2013년 10월 25일
편집: Matt J 2013년 10월 25일
Please format your code readably, using the
toolbar button.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2013년 10월 25일
idx=randi(n,n*resamples,1);
Y=sum(reshape(B(idx,:),n,[]),1);
Y=reshape(Y,resamples,[]);
  댓글 수: 1
Griselda
Griselda 2013년 10월 25일
Thak you very much. Griselda

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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