Java tutorial
//package com.java2s; public class Main { public static double[][] createTestFold(double[][] kernel, int numberOfFolds, int fold) { int foldStart = foldStart(kernel.length, numberOfFolds, fold); int foldEnd = foldEnd(kernel.length, numberOfFolds, fold); int foldLength = (foldEnd - foldStart); double[][] testKernel = new double[foldEnd - foldStart][kernel.length - foldLength]; for (int i = 0; i < foldEnd - foldStart; i++) { for (int j = 0; j < foldStart; j++) { testKernel[i][j] = kernel[i + foldStart][j]; } for (int j = foldEnd; j < kernel.length; j++) { testKernel[i][j - foldLength] = kernel[i + foldStart][j]; } } return testKernel; } public static int foldStart(int length, int numberOfFolds, int fold) { return Math.round((length / ((float) numberOfFolds)) * ((float) fold - 1)); } public static int foldEnd(int length, int numberOfFolds, int fold) { return Math.round((length / ((float) numberOfFolds)) * (fold)); } }