I m using ILNumerics to read and write from/to matfiles. I get some data from a database as object[,] because it contains numbers and headings (strings).
The data structure of object[,] loaddata
is a mixture of System.String
and System.Double
, first two columns and first row contains strings rest doubles. I want to write the doubles into the matfile. Dimensions are roughly loaddata[9000,500]
.
This is my very cumbersome detour via system arrays that doesnt even work:
ILArray<object> loaddata = DBQuery(....);
//this next line has error
var tempoobj = ToSystemMatrix<object>(loaddata["2:end", "1:end"]);
double[,] tempdouble = new double[500, 8784];
Array.Copy(tempoobj, tempdouble, tempoobj.Length);
ILArray<double> B = tempdouble;
using (ILMatFile matW = new ILMatFile())
{
B.Name = "power";
matW.AddArray(B);
matW.Write(@"C:\Temp\Test.mat");
}
with the ToSystemMatrix function from here How to convert ILArray into double[,] array? - which I couldnt make work.
any ideas how to simplify this? and also how to make that function work (as it is usefull anyways).
UPDATE
I made this work but it feels like going at it with a sledgehammer.... But here it comes:
object[,] loaddata = DBQuery(...);
for (int i = 0; i < loaddata.GetLength(0); i++)
{
loaddata[i, 0] = Convert.ToDouble(0);
loaddata[i, 1] = Convert.ToDouble(0);
}
for (int i = 0; i < loaddata.GetLength(1); i++)
{
loaddata[0, i] = Convert.ToDouble(0);
}
double[,] tempdouble = new double[loaddata.GetLength(0), loaddata.GetLength(1)];
Array.Copy(loaddata, tempdouble, loaddata.Length);
ILArray<double> B = tempdouble;
using (ILMatFile matW = new ILMatFile())
{
B.Name = "power";
matW.AddArray(B["1:end","2:end"].T);
matW.Write(@"C:\Temp\Test.mat");
}
I also tried to use ILCell instead but ILCell loaddata = DBQuery(...)
and cell(loaddata)
threw errors.
Any ideas how to make this more neat?