You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: RandPartDB.m
    path of file: ./repos/lrslibrary/algorithms/nmf/ManhNMF
    
    the code of the file until where you have to start completion: function [tr,vd,ts]=RandPartDB(gnd,trNum)
% partition dataset in three subsets
% gnd, class labels
% trNum, feature number selected individually
% copyright @ Guan Naiyang
% modified time:

    
function [tr,vd,ts]=RandPartDB(gnd,trNum)
% partition dataset in three subsets
% gnd, class labels
% trNum, feature number selected individually
% copyright @ Guan Naiyang
% modified time:
% 18/4/2010

lb = unique(gnd);
n = length(gnd);
nn = length(lb);
tr = [];
ts = [];
for j = 1:nn
    p_index = find(gnd==lb(j));
    index = randperm(length(p_index));
    tr = [tr, p_index(index(1:trNum))'];
    ts = [ts, p_index(index(trNum+1:(2*trNum)))'];
end