1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | public class Gr { // field private static RConnection c = null; static double[] dataX = { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; static double[] dataY = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; // constructor // method public static void Rstart() throws Exception { c = new RConnection(); } public static void Rclose() throws Exception { c.close(); } private static void getMatrix(double[] mat, int nrow, int ncol) throws Exception { // 1.Start Rstart(); // 2.Field ArrayList objs = new ArrayList(); ArrayList resultset = new ArrayList(); int total = mat.length; int start = 0; int criteria = ncol; // 3.Method c.assign("m", mat); double[][] mr = new double[nrow][ncol]; mr = c.parseAndEval("m<-matrix(m,nrow=" + nrow + ",ncol="+ncol+",byrow=T)", null, false).asDoubleMatrix(); for (double[] mrs : mr) { for (double mrss : mrs) { objs.add(mrss); } } while (criteria <= total) { for (int i = start; i < criteria; i++) { resultset.add(objs.get(i)); } System.out.println(resultset); resultset.clear(); start = criteria; criteria += ncol; } System.out.println("matrix: misson success"); // 4.End Rclose(); } public static void main(String[] args) throws Exception { getMatrix(dataY,2,5); } } | cs |
2018년 1월 16일 화요일
JAVA에서 RSERVE를 이용한 matrix 만들기
피곤하니 일단 코드만..
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기