Skip to content

Commit

Permalink
Update MatrixTools.cs
Browse files Browse the repository at this point in the history
Issue #492 Add simple matrix method. Required after removing aforementioned method duplication.
  • Loading branch information
towsey committed Jun 5, 2021
1 parent ffcbb3a commit f900757
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/TowseyLibrary/MatrixTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,27 @@ public static double[] Matrix2Array(double[,] matrix)
return newM;
}

/// <summary>
/// Multiplies the values in a matrix by a factor.
/// Used to convert log-energy values to decibels.
/// </summary>
public static double[,] MultiplyMatrixByFactor(double[,] matrix, int factor)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
double[,] newM = new double[rows, cols];

for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
newM[i, j] = matrix[i, j] * factor;
}
}

return newM;
}

public static double[,] LogTransform(double[,] matrix)
{
int rows = matrix.GetLength(0);
Expand Down

0 comments on commit f900757

Please sign in to comment.