Home > matpower7.1 > extras > syngrid > lib > sg_datasample.m

sg_datasample

PURPOSE ^

SG_DATASAMPLE Select K samples from DATA (without replacement)

SYNOPSIS ^

function [y, i] = sg_datasample(varargin)

DESCRIPTION ^

SG_DATASAMPLE  Select K samples from DATA (without replacement)
   Y = SG_DATASAMPLE(DATA, K)
   [Y, I] = SG_DATASAMPLE(DATA, K)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y, i] = sg_datasample(varargin)
0002 %SG_DATASAMPLE  Select K samples from DATA (without replacement)
0003 %   Y = SG_DATASAMPLE(DATA, K)
0004 %   [Y, I] = SG_DATASAMPLE(DATA, K)
0005 
0006 %   SynGrid
0007 %   Copyright (c) 2017-2018, Power Systems Engineering Research Center (PSERC)
0008 %   by Ray Zimmerman, PSERC Cornell
0009 %
0010 %   This file is part of SynGrid.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 input = varargin;
0013 n_inpput = length(input);
0014 data = input{1};
0015 k = input{2} ;
0016 N = length(data);
0017 
0018 if k > N
0019     error('sg_datasample: number of samples limited to size of data');
0020 end
0021 
0022 if n_inpput == 4
0023     if strcmp(input{3},'replace') && ~input{4}
0024         ii = (1:N);
0025         ord = rand(size(data(:,1)));
0026         [junk, j] = sort(ord);
0027         i = ii(j(1:k));
0028         y = data(i,:);
0029     end
0030 else
0031     i = randi(N,k,1);
0032     y = data(i,:);
0033 end
0034

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005