You can use repmat
function to replicate the elements of the array and then reshape the resulting array to the desired size.
Here's an example code:
main.m349 chars12 lines
Explanation:
repmat(originalArray, numberOfDuplicates, 1)
replicates the originalArray numberOfDuplicates
times along the rows.'
is the transpose operator.reshape(replicatedArray', [], numberOfDuplicates)'
reshapes the replicated array to have 160 elements, with 20 duplicates of each element in the original array.Note that the resulting finalArray
will be a 160-by-1 array. If you want it to be a row or column vector instead, you can use the transpose
or reshape
function.
gistlibby LogSnag