function outmat=rrepmat(inmat,d1,d2) %function outmat=rrepmat(inmat,d1,d2) % With inmat n1 x n2 x ... nk x 1, produces a matrix with dimensions % [d1 n1 n2 ... nk d2]. repmat cannot put d1 first. % should drop the automatic padding with nin 1's, as this can be accomplished % or not by adding 1's to d1 and d2. din=size(inmat); nin=length(din); nd1=length(d1); nd2=length(d2); while din(nin)==1 & nin>1 nin=nin-1; end outmat=repmat(inmat,[ones(1,nin) d1 d2]); outmat=permute(outmat,[nin+1:nin+nd1 1:nin nin+nd1+1:nin+nd1+nd2]);