matlab - How to arrange dimension order in multidimensional array for minimum run time? -


for example, have 3-by-4-by-5 array m. if have frequency manipulations like

m(:,:,rr) = 

where should place rr in 3 position of subscription?

in word, faster below?

m(rr,:,:) = a m 3-by-4-by-5 array

or

m(:,:,rr) = a m 4-by-5-by-3 array

try this:

n = 100000; rr = randi(size(a,1), n, 1)  tic; k = 1:n     a(rr(k),:,:) = k; end toc  tic; k = 1:n     b(:,:,rr(k)) = k; end toc 

i find first method mildly slower:

elapsed time 0.078342 seconds. elapsed time 0.066406 seconds. 

this makes sense me because matlab assigns matrices memory arrays going down rows first (and columns, , 3rd, 4th 5th etc dimensions). a(:,:,k) contiguous chunk of memory whereas a(k,:,:) not.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -