MATLAB/Python Engine Integration Optimizing for Execution Speed
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Steven Lord
il 3 Feb 2026 alle 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?
Risposte (0)
Vedere anche
Categorie
Scopri di più su Call MATLAB from Python in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


