MATLAB: How to randomly combine the elements of two arrays in MATLAB 7.5 (R2007b)

combineMATLABrandomize

I have two one dimensional arrays. I would like to combine them to create a third array with the elements in a random order.

Best Answer

The attached function 'mixarray.m' will combine two one dimensional arrays and randomize the order of their elements. The basic structure is as follows:
1. Combine the two arrays into one.
2. Create a random list of indices.
3. Assign the original data into a new array using the random list of indices.
A sample of how you could use this function follows:
>> A=[815 2 55];
>> B=[545 1 8];
>> C=mixarrays(A,B)
C =
8 2 545 815 55 1