Randomization of rows of two matrices with the same order
1 view (last 30 days)
Show older comments
Hi I want to randomize two matrixes rows with same order, e.g the 10th row of first matrix become 2nd row of that matrix after randomization. The second matrix should have the same order. ..... Anyone can help. Thanks
2 Comments
Oleg Komarov
on 2 Sep 2012
Please post example inputs, and desired output: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Answers (1)
Image Analyst
on 2 Sep 2012
Try this:
format compact;
format short;
% Generate some sample data.
m1 = randi(50, 4,2)
m2 = randi(50, 4,2)
% Find out how many rows we need to randomize.
numberOfRows = size(m1, 1)
% Get a new order for the rows.
newRowOrder = randperm(numberOfRows)
% Apply that order to both arrays.
new_m1 = m1(newRowOrder, :)
new_m2 = m2(newRowOrder, :)
In the command window:
m1 =
34 20
5 29
23 27
43 49
m2 =
2 22
30 36
4 46
43 3
numberOfRows =
4
newRowOrder =
2 3 1 4
new_m1 =
5 29
23 27
34 20
43 49
new_m2 =
30 36
4 46
2 22
43 3
0 Comments
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!