A=randi(5,7,3); F=randi(5,3,4); B=cell2mat(arrayfun(@(a,r)repmat(a,1,r),A,size(F,2)*ones(size(A)),'uni',0)).*repmat(reshape(F',[],numel(F)),size(A,1),1);