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 Center および File ExchangeJava Package Integration についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by