Passing object array from C# to MATLAB

조회 수: 2 (최근 30일)
Nolin Borrero Jr
Nolin Borrero Jr 2021년 1월 12일
편집: Nolin Borrero Jr 2021년 1월 13일
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