Fast transfer of .net array to matlab array.

조회 수: 12 (최근 30일)
Brian
Brian 2012년 8월 27일
I am calling a .net dll from matlab, which is working just fine. I get an image from the .net dll and then want to process it with matlab, before sending it back to .net. The problem is that most of the matlab functions do not work with the .net array, so I would like to change the .net array to a matlab array, do the processing, and then send it back to .net.
The problem is that I cannot find an efficient way to do this. Indexing the .net array, is painfully slow. There does not seem to be a built in function to do this transfer. Is there a good way to transfer an array of single to a matlab array?
  댓글 수: 1
Sven
Sven 2012년 8월 29일
Brian, sorry, no answer for you, but I'd be interested if you find some things out.
I suspect the "best" way to go about it will be to somehow override the .NET array access, find out where the first element is stored in memory, and then try to access the whole array at once. Obviously this is getting outside of vanilla MATLAB and a bit more into "undocumented" stuff...

댓글을 달려면 로그인하십시오.

채택된 답변

Friedrich
Friedrich 2012년 8월 29일
Hi,
actually its pretty fast. Working on that .NET Array directly is not that fast, but converting it into ML data type is fast:
my_array = NET.createArray('System.Single[]',100000);
disp('filling up with values => takes ages')
tic
for i=1:my_array.Length
my_array(i) = i;
end
toc
disp('convert to ML data type => pretty fast')
tic
ML_dlb_arr = my_array.double;
toc
When running this in MATLAB I get:
filling up with values => takes ages
Elapsed time is 20.732684 seconds.
convert to ML data type => pretty fast
Elapsed time is 0.028037 seconds.
So 0.03seconds for converting 100000 values from .NET to MATLAB is okay I think.
What size does your data have? How long does it takes for you?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by