www.pudn.com > snippets(1).rar > split_data.m, change:2009-10-12,size:596b


function [train_data, train_class, test_data, test_class] = split_data(data, class, st, ed)
%
% split data set into training and test part for leave-one-out test.

sz = length(data);
sz_test = ed-st+1;
sz_train = sz-sz_test;

curr_tr = 1;
curr_ts = 1;
for u = 1:sz

  if u>=st && u<=ed
    for v = 1:length(data{u})
      test_data{curr_ts} = data{u}{v};
      test_class(curr_ts) = class{u}(v);
      curr_ts = curr_ts+1;
    end
  else
    for v = 1:length(data{u})
      train_data{curr_tr} = data{u}{v};
      train_class(curr_tr) = class{u}(v);
      curr_tr = curr_tr+1;
    end
  end

end