MATLAB: Fill in a matrix

elementsfill-inmatrixrandom integers

I want to create a row matrix of 16 elements and fill in the first 8 elements (as well as the last 8 elements) of it, with integers from 1 to 8.
i.e. result = ( 2 5 2 8 4 1 4 7 3 5 3 7 8 4 6 6 )
Any help could be useful. thanks in advance!

Best Answer

This seems to do what you want:
result = randi([1 8], 1, 16)
producing:
result =
4 1 3 3 3 2 3 1 8 1 8 4 1 3 6 7