MATLAB: Convert a vector to vector sequentially

MATLABvector matrix

I have 2 vector: init = [1 2 3 4], final =[5 6 7 8]. I would like to genertate all the vector like the following:
[1 2 3 4] [5 2 3 4] [5 6 3 4] [5 6 7 4] [5 6 7 8]. Is there anyway to do this fast using some special function available in matlab?

Best Answer

%assuming init and final are the same size!!
init = [1 2 3 4];
final =[5 6 7 8];
output = repmat(init(:), 1, length(init));
toutput = repmat(final(:), 1, length(init));
mask = triu(true(size(output)),1);
output(mask) = toutput(mask);
And now the outputs are down the columns. If you really want vectors,
num2cell(output,1)