MATLAB/Python Engine Integration Optimizing for Execution Speed
조회 수: 22 (최근 30일)
이전 댓글 표시
I have a function in MATLAB that I've timed to run at about 0.25 seconds per iteration using tic/toc. However, because of integration with other systems, I'm trying to call that function from Python using the MATLAB Engine by passing in a few input parameters: namely three vectors around ~5000, ~5000, and ~60000 elements (the return is a single double value):
eng.runFxn(obj, matlab.double(v1), matlab.double(v2), matlab.double(v3), float(i + 1))
However, this has been slower by an order of magnitude, running at around 3-4 seconds per iteration (using time.time()). I'm just wondering if this is expected behavior/if there's any way to speed up the inter-language communication speed, or if this approach may be a lost cause and I need to find a different method to execute the MATLAB script.
댓글 수: 2
Steven Lord
2026년 2월 3일 20:36
I have a function in MATLAB that I've timed to run at about 0.25 seconds per iteration using tic/toc.
With the same input arguments that you're passing into the function when you call it from Python?
However, this has been slower by an order of magnitude, running at around 3-4 seconds per iteration (using time.time()).
Where is the time being taken? In the function call itself, in the conversion of the data to double with matlab.double, or somewhere else? If it is the conversion that's the bottleneck, can you perform that conversion prior to the start of the loop where you're iteratively calling the function to limit the number of times you need to convert?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


