matlab - the fastest way to replicate a vector in two direction -
i have vector want replicate elements in both row , column directions. have found using ones
built-in function faster m-file functions repmat
, kron
. have seen examples replicating vector in 1 direction, not find how in both direction.
consider following example:
a = [1 2 3];
i want create these matrices:
b = [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3];
and
c = [1 2 3 1 2 3 1 2 3 1 2 3];
how can ones
? there faster way?
in code, vectors replicated bigger , have many vectors in for
loop. looking faster way.
how if had matrix replicated? example:
d = [1 2 3 4 5 6];
and want have:
e = [1 2 3 1 2 3 4 5 6 4 5 6 1 2 3 1 2 3 4 5 6 4 5 6];
c
, e
straightforward cases repmat
. b
different, common suggestion use kron(a', ones(2,3))
here alternatives: a similar function r's rep in matlab
according many answers in link, fastest possibly
reshape(repmat(a, 6, 1), 3, 6)'
Comments
Post a Comment