Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transpose matrix?

I have made 8x8 matrix using c#, and now I need to transpose the matrix. Can you help me to transpose the matrix? This is my matrix

public double[,] MatriksT(int blok)
{
    double[,] matrixT = new double[blok, blok];

    for (int j = 0; j < blok ; j++)
    {
        matrixT[0, j] = Math.Sqrt(1 / (double)blok);

    }

    for (int i = 1; i < blok; i++)
    {
        for (int j = 0; j < blok; j++)
        {
            matrixT[i, j] = Math.Sqrt(2 / (double)blok) * Math.Cos(((2 * j + 1) * i * Math.PI) / 2 * blok);
        }
    }

    return matrixT;

}
like image 521
Reza Agustina Avatar asked Apr 07 '15 04:04

Reza Agustina


1 Answers

public double[,] Transpose(double[,] matrix)
{
    int w = matrix.GetLength(0);
    int h = matrix.GetLength(1);

    double[,] result = new double[h, w];

    for (int i = 0; i < w; i++)
    {
        for (int j = 0; j < h; j++)
        {
            result[j, i] = matrix[i, j];
        }
    }

    return result;
}
like image 129
jan Avatar answered Sep 26 '22 00:09

jan