From: William on 30 Apr 2010 16:39 I have a vector v with length n I want to generate matrix m with size a-by-b-by-n such that m(:,:,i) = v(i)*ones(a,b), for i = 1,2,...,n Is there any function that can generate this matrix in one line, my code does not allow me to use loop. Thanks!
From: Matt Fig on 30 Apr 2010 16:54 bsxfun(@times,ones(a,b,length(v)),reshape(v,1,1,[]))
From: Steven Lord on 30 Apr 2010 17:22 "William " <huyichuan(a)gmail.com> wrote in message news:hrff58$rum$1(a)fred.mathworks.com... >I have a vector v with length n > > I want to generate matrix m with size a-by-b-by-n such that > > m(:,:,i) = v(i)*ones(a,b), for i = 1,2,...,n > > Is there any function that can generate this matrix in one line, my code > does not allow me to use loop. % sample data a = 2; b = 3; n = 10; v = 1:n; M = repmat(reshape(v, [1 1 n]), a, b); -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: converting cell array to matrix of doubles with NaN's Next: Resample vector/matrix |