1

H I'm using VB.NET, and i have a two dimensional array. How do I extract a one-dimensional array from it? I.E the 3rd row.

Something like MAT[0] which i would do in java to get the first row from a matrix.

Thanks.

2
  • 3
    Can you show the code fragment where you define the 2 dimensional array? Commented Jun 3, 2013 at 15:07
  • Public RXUser_Array(14, 257) As Byte. That's how it's declared. Thanks. Commented Jun 3, 2013 at 15:11

2 Answers 2

1

Use parenthesis instead ob brackets:

mat(0)
Sign up to request clarification or add additional context in comments.

2 Comments

Tried that. It says "number of indices is less than the number of dimensions of the indexed array"
Sorry. is's mat(0)(0) or the index you want to get.
1

I think you have to write a simple function to get a single row as an array, for example:

Private Function GetRow(matrix As Byte(,), row_number As Integer) As Byte()
    'get the number of columns of your matrix
    Dim number_of_columns As Integer = matrix.GetLength(1)

    'define empty array, at the end of the 'for' cycle it will contain requested row's values  
    Dim values As Byte() = Nothing

    For i As Integer = 0 To number_of_columns - 1
        'Resize array
        ReDim Preserve values(i)
        'Populate array element
        values(i) = matrix(row_number, i)
    Next

    Return values

End Function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.