select Column from Matrix - Java java.lang

Java examples for java.lang:Math Matrix

Description

select Column from Matrix

Demo Code

/*/*from  w w w  . j ava2  s.  c  o  m*/
 *  Java Information Dynamics Toolkit (JIDT)
 *  Copyright (C) 2012, Joseph T. Lizier
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

public class Main {
    public static int[] selectColumn(int matrix[][], int columnNo) {
        int[] column = new int[matrix.length];
        for (int r = 0; r < matrix.length; r++) {
            column[r] = matrix[r][columnNo];
        }
        return column;
    }

    public static double[] selectColumn(double matrix[][], int columnNo) {
        double[] column = new double[matrix.length];
        for (int r = 0; r < matrix.length; r++) {
            column[r] = matrix[r][columnNo];
        }
        return column;
    }

    public static double[] selectColumn(double matrix[][], int columnNo,
            int startRow, int rows) {
        double[] column = new double[rows];
        for (int r = 0; r < rows; r++) {
            column[r] = matrix[startRow + r][columnNo];
        }
        return column;
    }

    public static int[] selectColumn(int matrix[][], int columnNo,
            int startRow, int rows) {
        int[] column = new int[rows];
        for (int r = 0; r < rows; r++) {
            column[r] = matrix[startRow + r][columnNo];
        }
        return column;
    }

    public static byte[] selectColumn(byte matrix[][], int columnNo,
            int startRow, int rows) {
        byte[] column = new byte[rows];
        for (int r = 0; r < rows; r++) {
            column[r] = matrix[startRow + r][columnNo];
        }
        return column;
    }
}

Related Tutorials