Note that there are some explanatory texts on larger screens.

plurals
  1. POmatlab: sorting and random
    primarykey
    data
    text
    <p>I need to sort out few small matrices from 1 huge raw matrix ...according to sorting 1st column (1st column contain either 1, 2, or 3)...</p> <p>if 1st column is 1, then randomly 75% of the 1 save in file A1, 25% of the 1 save in file A2. </p> <p>if 1st column is 2, then randomly 75% of the 2 save in file B1, 25% of the 2 save in file B2.</p> <p>if 1st column is 3, then randomly 75% of the 3 save in file C1, 25% of the 3 save in file C2.</p> <p>how am i going to write the code?</p> <p>Example:</p> <p>a raw matrix has 15 rows x 6 columns:</p> <p>7 rows are 1 in 1st column, 5 rows are 2 in 1st column, and 3 rows are 3 in 1st column.</p> <pre><code>1 -0.05 -0.01 0.03 0.07 0.11 1 -0.4 -0.36 -0.32 -0.28 -0.24 1 0.3 0.34 0.38 0.42 0.46 1 0.75 0.79 0.83 0.87 0.91 1 0.45 0.49 0.53 0.57 0.61 1 0.8 0.84 0.88 0.92 0.96 1 0.05 0.09 0.13 0.17 0.21 2 0.5 0.54 0.58 0.62 0.66 2 0.4 0.44 0.48 0.52 0.56 2 0.9 0.94 0.98 1.02 1.06 2 0.85 0.89 0.93 0.97 1.01 2 0.75 0.79 0.83 0.87 0.91 3 0.36 0.4 0.44 0.48 0.52 3 0.6 0.64 0.68 0.72 0.76 3 0.4 0.44 0.48 0.52 0.56 </code></pre> <p>7 rows got 1 in 1st column, randomly take out 75% of 7 rows (which is 7*0.75=5.25) to be new matrix (5rows x 6 columns), the rest of 25% become another new matrix</p> <p>5 rows got 2 in 1st column, randomly take out 75% of 5 rows (which is 5*0.75=3.75) to be new matrix (4rows x 6 columns), the rest of 25% become another new matrix</p> <p>3 rows got 3 in 1st column, randomly take out 75% of 3 rows (which is 3*0.75=2.25) to be new matrix (2rows x 6 columns), the rest of 25% become another new matrix</p> <p>Result:</p> <pre><code>A1= 1 -0.4 -0.36 -0.32 -0.28 -0.24 1 0.3 0.34 0.38 0.42 0.46 1 0.75 0.79 0.83 0.87 0.91 1 0.8 0.84 0.88 0.92 0.96 1 -0.05 -0.01 0.03 0.07 0.11 B1= 2 0.9 0.94 0.98 1.02 1.06 2 0.85 0.89 0.93 0.97 1.01 2 0.5 0.54 0.58 0.62 0.66 2 0.75 0.79 0.83 0.87 0.91 C1= 3 0.36 0.4 0.44 0.48 0.52 3 0.4 0.44 0.48 0.52 0.56 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload