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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2013 年 10 月 25 日

コメント済み:

2013 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by