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

前端 未结 1 1501
温柔的废话
温柔的废话 2020-12-10 08:18

I have a matrix and a vector each with 3000 rows:

fe = [-0.1850   -0.4485; ...
      -0.2150    2.6302; ...
      -0.2081    1.5883; ...
      -0.6416   -1.1         


        
1条回答
  •  温柔的废话
    2020-12-10 08:46

    Assuming you need to select 2/3 of the rows and both the columns, you can do

    feTrain=fe(1:2000,:);
    feTest=fe(2001:end,:);
    

    If you wanted to assign 2/3 of the rows picked randomly (i.e., not the first 2/3), you can use the randperm function to generate random ordering of the row indices and use that to index.

    nRows=size(fe,1);
    randRows=randperm(nRows);%# generate random ordering of row indices
    feTrain=fe(randRows(1:2000),:);%# index using random order
    feTest=fe(randRows(2001:end),:);
    

    0 讨论(0)
提交回复
热议问题