performance - How can I fill a matrix with all the N-Ary numbers fast? -
it stupid trying having 7 column matrix consisiting mod 7 numbers , takes huge time generate such matrix utilizing following code
to = 7^k; msgvalue = zeros(to,k); l=0:to kcounter=0:(k-1) msgvalue(l+1,kcounter+1)=mod((l/7^kcounter),7); end end msgvalue = floor(msgvalue);
how can faster?
or vectorized approach (direct matrix multiplication):
msgvalue = floor( mod( (0:7^k).' * (1./(7.^(0:k-1))),7 ) ) ;
a wee bit faster famous bsxfun
;-)
%// 10000 iterations, k=3 elapsed time 2.280774 seconds. %// double loop elapsed time 1.329179 seconds. %// bsxfun elapsed time 0.958945 seconds. %// matrix multiplication
Comments
Post a Comment