1

Possible Duplicate:
How can I divide/split up a matrix by rows between two other matrices?

I have a matrix A with 100 rows, I want to randomly partition it into 2 matrices, one that will have 70 of the rows of A, and the other that will have the remaining 30 rows. How is this done?

Community
  • 1
  • 1
Glup
  • 11
  • 1
  • 2
  • Well, it's *technically* not a duplicate since Glup is asking how to "randomly partition", not simply cut the matrix after row 70. – gnovice Apr 06 '11 at 14:55
  • 1
    @gnovice: the answer to the duplicate question uses `randperm` to generate two random fractions. The difference is in one question, it's 1/3 vs 2/3, while in the other, it's 0.3 vs 0.7. – Jonas Apr 06 '11 at 15:04
  • 1
    @Jonas: Oops, I didn't see any mention of randomness in that other *question*, but it is in the *answer*. That question should certainly be edited to clean it up and make it more general so it can be easily found in the future. – gnovice Apr 06 '11 at 15:11
  • @gnovice: done-ish. Please have a look whether it could use some more improvement. – Jonas Apr 06 '11 at 15:21

1 Answers1

0

Its quite some time that I really used Matlab, but this should work: At first we look for a random number to split the matrix. Then we store all rows up to this factor in B, the rest is stored in C

split = round(rand(1)*100);
B = A[1:split, :];
C = A[(split+1):100, :];
Chris
  • 2,030
  • 1
  • 16
  • 22
  • Well, this is splitting, as you said. It puts consecutive rows together in the same partition. This is not what I want. I want it to be possible, for example, to have the first, fifth row in the first partition, and the second, third,...sixth etc in the second – Glup Apr 06 '11 at 14:45
  • Oh sorry, then I misunderstood you. I thought that just the splitting point should be random. Anyway, See the link of Jonas under your question,it should answer your problem – Chris Apr 06 '11 at 14:50