How can I randomly combine the elements of two arrays in MATLAB 7.5 (R2007b)?

11 views (last 30 days)
I have two one dimensional arrays. I would like to combine them to create a third array with the elements in a random order.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2007b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!