How can I spped up my shuffle test for a large array?

조회 수: 2 (최근 30일)
Meng Wang
Meng Wang 2020년 5월 20일
I'm working on shuffling a large array(Jy) which is about 400 (numtrial)x 5(numtaper) x 80(numf) x 96(npair). I need to shuffle the first dimension for each column. My way is: 1.generate the index array by randperm, e.g. index is a 400 x 500(nPerm) matrix; 2.repmat the index array up to 400 x 5 x 80 x 96 x 500; 3.repmat the original array up to 400 x 5 x 80 x 96 and index the original large array by the index array to fully shuffle it. But it costs a large amount of time at the third step which is to index a huge array. Do you have any idea to improve this and save time?
%first step
I = zeros(numtrial,1,1,1,nPerm);
for iP = 1:nPerm
I(:,1,1,1,iP) = randperm(numtrial);
end
%second step
i = numtrial*((1:1:(numtaper*numf*npair*nPerm))-1);
I = repmat(I,1,numtaper,numf,npair,1)+reshape(i,1,numtaper,numf,npair,nPerm);
%third step
Jyrand = repmat(Jy,1,1,1,1,nPerm);
Jyrand = Jyrand(I);%this line costs too much time

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by