Anonymous function versus File in matlabfunction

4 ビュー (過去 30 日間)
Brad Humphreys
Brad Humphreys 2016 年 12 月 22 日
回答済み: Walter Roberson 2016 年 12 月 22 日
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 Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by