Sampling data in MATLAB

后端 未结 1 1177
误落风尘
误落风尘 2021-01-19 05:39

I have two pieces of data. One is the actual fulldata which is a dataset of 49625x6 numeric data, and the other is the index of that data with the target_class

相关标签:
1条回答
  • 2021-01-19 06:21

    Extract the 'normal' records using strmatch:

    normIdx = strmatch('normal.', Book2);
    normalSubset = fulldata(normIdx, :);
    

    Then to generate a list of 250 random non repeating integers I googled "matlab list of non repeated random integers" and from the first result:

    p = randperm(size(normalSubset , 1));
    p = p(1:250)-1;
    

    So now to get your 250 randomly selected normal records

    normalSample = normalSubset (p, :);
    

    normalSample will be 250 x 6. now do the same with 'not normal.' to get a notNormalSample (750 x 6) and then combine then to get

    sample = [normalSample ; notNormalSample ]
    

    So in sample all the normals will appear before the not normals, if you want to mix them up use randperm() again:

    sample = sample(randperm(1000), :);
    
    0 讨论(0)
提交回复
热议问题