One simple option is to use a temporary variable for this:
a = [2 4 6 8]; k = 7; tmp = repmat(a,1,ceil(k/numel(a))); aa = tmp(1:k)
First, you repeat the vector using the smallest integer, which makes the result larger than k , and then you remove the extra elements.
If you do this many times, you can write a small helper function for this:
function out = semi_repmat(arr,k) tmp = repmat(arr,1,ceil(k/numel(arr))); out = tmp(1:k); end
source share