How to add matrices dimension by dimension without using a loop?
조회 수: 3(최근 30일)
I've got this huge loop that takes a lot of time to be computed:
J(i1,j1,i2,j2,j3) = (ldp(i2,j2,j3) - ld(i1,j1,j2))*pdf_transp(i1,j1,i2,j2,j3);
xN and zN are 300 and 7 for now, but it easily takes several minutes to compute.
I have tried to use repmat and permute and then do something like this
ld_old = permute(repmat(ld,[1 1 1 xN zN]),[1 2 4 3 5]);
ld_new = permute(repmat(ldp,[1 1 1 xN zN]),[4 5 1 2 3]);
J2 = (ld_new(:)-ld_old(:)).*pdf_transp(:);
That is much faster, but still pretty slow. Is there a more efficient way for this kind of operation?