Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

pick_n.m 739 B

123456789101112131415161718192021222324252627282930313233343536
  1. function y = pick_n(list, n, varargin)
  2. % y = pick_n(list, n, ['with_replacement', false])
  3. % if the list is a matrix return random rows of the matrix.
  4. %
  5. % Optional inputs
  6. % with_replacement [false]
  7. with_rep = utils.inputordefault('with_replacement',false,varargin);
  8. if isvector(list)
  9. if isrow(list)
  10. list = list(:);
  11. rowflag = true;
  12. else
  13. rowflag = false;
  14. end
  15. else
  16. rowflag = false;
  17. end
  18. num = size(list,1);
  19. if with_rep
  20. ind = randi(num, [n,1]);
  21. else
  22. if n > num
  23. error('utils:pick_n','You cannot select %d elements from a list of size %d without replacement',n,num)
  24. else
  25. perm = randperm(num);
  26. ind = perm(1:n);
  27. end
  28. end
  29. y = list(ind,:);
  30. if rowflag
  31. y = y';
  32. end