MATLAB: Repmat a vector n times where n is not a whole number

repmat

I have a vector y consisting out of 10 elements. I want have a for loop, where I repmat the vector y to a new vector. However repmat is not working since n is not always a whole number. In this case I want it to choose the element which is next, e.g. if n = 4.2 it should take y 4 times and add element 1 and 2 separately. How can I do this?
y = [1:10];
for n = 4:0.5:6
Z = repmat(y,n,1);
end

Best Answer

To take the smaller index (equivalent to fix):
>> y = 1:10;
>> n = 4.2;
>> [repmat(y,1,fix(n)),y(1:numel(y)*mod(n,1))]
ans = 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2