performance - Efficiently creating a certain matrix with MATLAB -
i have 1 x n vector , 1 x m vector b. want create n x m matrix j-th row vector a(j) * b. have been doing in matlab with
[m1, m2] = meshgrid(b, a); m = m1.*m2
since n, m big in problem, looking efficient way create matlab this, , suspect makeshift hack not answer. in advance help!
try
m = bsxfun(@times, a.', b);
on computer, several times faster original code vectors thousands of elements.
performance matlab matrix vectorization
No comments:
Post a Comment