请参考大神解释:
https://blog.csdn.net/Autumn_He/article/details/81081528
附代码演示:
Data = csvread('../../exampledata/ERA.csv');
targets = Data(:,end);
k = 10;
CVO = cvpartition(targets,'KFold',k)
nameDataset = 'niuniu';
rootDir = fullfile('..','..','exampledata',nameDataset)
mkdir(rootDir)
for ff = 1:k
trIdx = CVO.training(ff)
teIdx = CVO.test(ff);
dlmwrite(fullfile(rootDir,sprintf('train-%s.%d',nameDataset,ff-1)),Data(trIdx,:),'')
dlmwrite(fullfile(rootDir,sprintf('test-%s.%d',nameDataset,ff-1)),Data(teIdx,:),'')
end