# Transpose of a matrix

When the rows of matrix are converted into column
and columns are converted into row then
that matrix is called transpose of a matrix.
This code shows how to create transpose of a matrix.

``Private Sub Transpose()        Dim strArray As String = ""        'Create matrix M1 and M2.        Dim M1(3, 3), M2(3, 3) As Integer        Dim intValue As Integer = 10        Dim intI, intJ As Integer        'intI represents row and         'intJ represents column of all the matrices.        'The intI in the for loop considers         'all the rows and intJ considers all        'the columns.So row is considered first        'and then the column, while performing        'every operation over matrix.        'Add data in first matrix M1.        'Here the first element is 10 and        'then it is incremented by 10.        For intI = 0 To 2            For intJ = 0 To 2                'Value is saved in each cell of matrix                M1(intI, intJ) = intValue                intValue = intValue + 10            Next        Next        'Display the original matrix M1.        For intI = 0 To 2            For intJ = 0 To 2                If strArray.Length = 0 Then                    strArray = "   " & M1(intI, intJ)                Else                    strArray = strArray & "   " & M1(intI, intJ)                End If            Next            strArray = strArray & vbNewLine        Next        MessageBox.Show("The original matrix is " & vbNewLine & strArray)        For intI = 0 To 2            For intJ = 0 To 2                'In the matrix M2 ,transponse of matrix                 'is saved.Rows are converted in columns and                'columns are converted into rows.In the matrix M1,                'intI represents row and intJ represents column.                'While saving value in M2,columns of matrix M1                'are considered first and then rows.                M2(intI, intJ) = M1(intJ, intI)            Next        Next        'The transponse of matrix is displayed.        strArray = ""        For intI = 0 To 2            For intJ = 0 To 2                If strArray.Length = 0 Then                    strArray = "   " & M2(intI, intJ)                Else                    strArray = strArray & "   " & M2(intI, intJ)                End If            Next            strArray = strArray & vbNewLine        Next        MessageBox.Show("The transpose of matrix is " & vbNewLine & strArray)    End Sub``

No responses found. Be the first to comment...

• Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
• No HTML formatting and links to other web sites are allowed.
• This is a strictly moderated site. Absolutely no spam allowed.
• Name:
Email: