Java Matrix Swap swapColumns(double[][] front, int colA, int colB)

Here you can find the source of swapColumns(double[][] front, int colA, int colB)

Description

swap Columns

License

LGPL

Declaration

public static void swapColumns(double[][] front, int colA, int colB)
            throws Exception 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static void swapColumns(double[][] front, int colA, int colB)
            throws Exception {

        if (front.length == 0 || (colA > front.length)
                || (colB > front.length))
            throw new Exception("Selected dimensions exceed front size");
        else {/*from   w w  w  . jav a2 s . c om*/

            int setPointMin = Math.min(colA, colB);
            int setPointMax = Math.max(colA, colB);

            for (int i = 0; i < front.length; i++) {
                double back = 0.0;
                for (int j = 0; j < front[0].length; j++) {
                    if (j == setPointMin) {
                        back = front[i][j];
                        front[i][j] = front[i][setPointMax];
                    }
                    if (j == setPointMax) {
                        front[i][j] = back;
                    }
                }
            }
        }

    }
}

Related

  1. swap(double[][] noteOrder, final int i, final int j)
  2. swap2d(Object[][] array, int c1, int r1, int c2, int r2)
  3. swapColumns(byte[][] matrix, int a, int b)
  4. swapColumns(int i, int j, boolean[][] matrix)
  5. swapRows(double[][] a, int i, int j)
  6. swapRows(double[][] Ab, int k, int i)
  7. swapRows(double[][] matrix, int i1, int i2)