Passing object array from C# to MATLAB

2 次查看(过去 30 天)
I have a program where I have to basically send a database to from C# code to MATLAB. If I do this using the COM interface, then I just send a giant object[,] array and it works fine. It sends it pretty much instantly. If I am using the MCR with a compiled .dll, then I have to convert this data to a giant MWCellArray. This table is pretty big (65,000 x 365). Converting this to the MWCellArray takes too long. I am using this because the type of data in each cell is not consistent.
Is there an alternative to using a MWCellArray that would allow me to send a large object array with arbitrary data from C# to the MATLAB Runtime?
I am using the compiled runtime for R2017a.

采纳的回答

Nolin Borrero Jr
Nolin Borrero Jr 2021-1-13
编辑:Nolin Borrero Jr 2021-1-13
So I think I found a solution but I don't understand why it works. If anyone knows, please let me know.
My old code was:
MWCellArray output = new MWCellArray(rows, columns);
for (int i =0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
output[i+1, j+1] = WrapObject<T>(input[i, j]);
}
}
return output;
In this code, T might be MWCellArray and an empty MWCellArray would be returned if the input value is null. I think this was a big part of the problem.
Changing WrapObject to return null and using this to this code speeds it up a little:
MWCellArray output = new MWCellArray(rows, columns);
for (int i =0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
MWArray value = WrapObject<T>(input[i, j]);
if (value != null)
output[i+1, j+1] = value;
}
}
return output;
But this is what actually works and takes probably 5% as long as the original code:
MWArray[,] cache = new MWArray[rows, columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
MWArray value = WrapObject<T>(input[i, j]);
if (value != null)
cache[i, j] = value;
}
}
MWCellArray output = new MWCellArray(rows, columns);
for (int i =0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
MWArray value = cache[i, j];
if (value != null)
output[i+1, j+1] = value;
}
}
Why does building directly on the MWCellArray slow everything down?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by