MATLAB: Repeating each array value a specific number of times

arrays

Is there an efficient way of repeating each element of i for j times in a 1xk matrix where k=ixj?
% temp file
k=1;
d=[];
for i = 1:31
j(1:24) = k;
d = [d j];
k=k+1;
end

Best Answer

k = 1:31;
a = k(ones(1, 24), :); % Or: repmat(k, 24, 1)
d = transpose(a(:));