Created
June 12, 2013 18:36
-
-
Save ajfigueroa/5767885 to your computer and use it in GitHub Desktop.
An implementation I made a while back of the repmat() function since the API I was using did not have it implemented it at the time.
I would love to know different ways of approach this problem, it was meant to work with MathNetNumerics library matrices but it can be adjusted to fit a 2D array of any type (not just Doubles).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' <param name="matrix">The matrix to be tiled</param> | |
''' <param name="row">The row dimension of result matrix</param> | |
''' <param name="column">The column dimension of result matrix</param> | |
''' <returns>The tiled and replicated matrix.</returns> | |
Function repmat(ByVal matrix As Matrix(Of Double), ByVal row As Integer, ByVal column As Integer) As Matrix(Of Double) | |
' Initialize the proper dimensions of the new matrix | |
Dim result As Matrix(Of Double) | |
result = New DenseMatrix(matrix.RowCount * row, matrix.ColumnCount * column) | |
' Used to keep track of indices | |
Dim m As Integer | |
Dim n As Integer | |
m = 0 | |
For i As Integer = 0 To result.RowCount - 1 | |
n = 0 | |
For j As Integer = 0 To result.ColumnCount - 1 | |
result.Item(i, j) = matrix.Item(m, n) | |
n += 1 | |
If n = matrix.ColumnCount Then | |
' n is equal to number of columns of matrix and time to reset | |
n = 0 | |
End If | |
Next | |
m += 1 | |
If m = matrix.RowCount Then | |
'm is equal to number of rows of matrix and time to reset | |
m = 0 | |
End If | |
Next | |
Return result | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment