Anonymous function versus File in matlabfunction

1 vue (au cours des 30 derniers jours)
Brad Humphreys
Brad Humphreys le 22 Déc 2016
I am creating several large functions from symbolic expressions (jacobians used in optimization).
I've noticed that it takes some time to create the file output using
matlabFunction(jacob,'File','jacobianFunctinName','Vars',{listOfSymbolicVars})
Using an anonymous function, it is MUCH faster:
jacfun=matlabFunction(jacob,'Vars',{listOfSymbolicVars})
Is there a reason for this (profiling the code points out matlabWrite)? I know that anonymous functions were slower in past releases; should I pay the price up front to make the file, or just use the anonymous function?
Thanks,
Brad

Réponses (1)

Walter Roberson
Walter Roberson le 22 Déc 2016
"By default, matlabFunction with the File argument generates a file containing optimized code. Code optimization means that intermediate variables are used to simplify or speed up the code. MATLAB generates intermediate variables as a lowercase letter t followed by an automatically generated number, for example t32.
matlabFunction without the File argument (or with a file path specified by an empty character vector) creates a function handle. In this case, the code is not optimized. If you try to enforce code optimization by setting Optimize to true, then matlabFunction throws an error."

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by