function [itrn,itst]=crossval(num_data,num_folds)
% CROSSVAL partions data for cross-validation.
% [itrn,itst]=crossval(num_data,num_folds)
%
% Inputs:
%  num_data [int] number of data.
%  num_folds [int] number of splitting (folders) to traning
%       and testing part.
%
% Output:
%  itrn{i} [ints] indices of training data.
%  itst{i} [ints] indices of testing data.
%

% Modif:
%  29-oct-2002, VF

% random partitioning 
inx=randperm(num_data);

itrn=cell(1,num_folds);
itst=cell(1,num_folds);

num_column=ceil(num_data/num_folds);
part=[1:num_data zeros(1,num_column*num_folds-num_data)];
part=reshape(part,num_column,num_folds)';

for i=1:num_folds,
  tst_inx=part(i,:);
  tst_inx=tst_inx(find(tst_inx));
  trn_inx=part(find([1:num_folds]~=i),:);
  trn_inx=trn_inx(find(trn_inx));

  itrn{i}=inx(trn_inx);
  itst{i}=inx(tst_inx);
end

return;

