-1

So, I have a matrix called matrix1 (dimensions = 1280x5, with each element being a number). I have another matrix, called matrix2, which has the same dimensions and contains all zeros). Here's what I want to do: randomly select one row from matrix1 WITHOUT REPLACEMENT and insert it into row one of matrix2. The next randomly selected row from matrix1 would go in row 2 of matrix 2, and so on until all 1280 rows of matrix1 have been moved to matrix 2. Notably, I want all of this to happen using a for loop with 1280 iterations. On each iteration, 1 row from matrix will be selected at random without replacement and put into matrix 2. Please let me know if you have any suggestions.

Thanks!

G

  • It is possible to go without the for loop, is the for loop a necessary requirement? – GameOfThrows Aug 24 '15 at 09:54
  • I'm building a famous psychology experiment, consisting of 1280 trials, so it doesn't seem feasible to not use a for loop.... but I could be wrong as I'm still a beginner with MATLAB..any other suggestions? – FastBallooningHead Aug 25 '15 at 07:09

1 Answers1

1

You can do that with the proper indexing for the rows:

idx = randperm(size(mat1,1));   %// Random row index
mat2 = mat1(idx, :);
josoler
  • 1,393
  • 9
  • 15