This can be easily done by addressing the vector correctly. First you need a random order to shuffle your elements. You can do that by using rand and then sort:
so b will be the order. Now you need to use that to re-order your vector, let's call the new vector A2:
A2 = [A(1) A(b+1) A(end)]
Now you have a new vector with the first and last same as they were, but 2:4 have been randomly shuffled.
Hope this solves your question.