How can I remove for loops?

5 次查看(过去 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,[]);

更多回答(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