I couldn't find a MatFileHandler native way to handle conversion of 2-dimensional jagged arrays into an IArray representing a MATLAB matrix, so I coded this simple extension method that could be added/enhanced/adapted to native MatFileHandler.
It can also be adapted for inputs of type T[,]
public static class MyExtensionMethods
{
public static IArrayOf<T> NewArray<T>(this DataBuilder matDataBuilder, T[][] data, params int[] dimensions)
where T : struct
{
var array = matDataBuilder.NewArray<T>(dimensions);
var m = data.Length;
var n = data[0].Length; // assuming the jagged array represents a 2d matrix; it could be checked though
for (var i = 0; i < m; i++)
{
for (var j = 0; j < n; j++)
{
array[j * m + i] = data[i][j];
}
}
return array;
}
}
I couldn't find a MatFileHandler native way to handle conversion of 2-dimensional jagged arrays into an IArray representing a MATLAB matrix, so I coded this simple extension method that could be added/enhanced/adapted to native MatFileHandler.
It can also be adapted for inputs of type
T[,]