Anonymous function versus File in matlabfunction

1 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2016-12-22
"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."

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by