Why is matlabFunction so slow?

16 views (last 30 days)
Sujit Nair
Sujit Nair on 27 Jul 2011
Commented: Walter Roberson on 8 Feb 2019
For example, the following code
test = sym(zeros(150,150));
fhandle = matlabFunction(test);
takes about 26 seconds! Is there any way to speed this routine?
  1 Comment
Walter Roberson
Walter Roberson on 8 Feb 2019
For whatever it is worth, on my late 2013 iMac running R2018b, the above takes less than 8 seconds.

Sign in to comment.

Answers (3)

Jan on 27 Jul 2011
What a funny question.
Of course the runtime depends on the matlabFunction. So please post its code. Otherwise there is absolutely no chance that we can guess where the function could be accelerated.

Sujit Nair
Sujit Nair on 27 Jul 2011
Thanks for the humorous answers :)
matlabFunction is MATLAB's own internal function to convert symbolic expressions to function handles or function files. See
for example.
Daniel Shub
Daniel Shub on 27 Jul 2011
I have the symbolic toolbox and I could not find the function. I tried
>> matlabFunction
??? Undefined function or variable 'matlabFunction'.
and assumed it was not a function. Of course I should have done
>> which -all matlabFunction
/usr/local/matlab/r2011a/toolbox/symbolic/symbolic/@sym/matlabFunction.m % sym method

Sign in to comment.

Giovanni on 27 Jul 2011
I have used matlabFunction for relatively complicated formulas and it doesn't seem too slow. Your example is unrealistic and I don't know exactly how Matlab would process it and why it takes so long. Can you post the actual function you are trying to create a handle out of? That way we might be able to help!
Walter Roberson
Walter Roberson on 8 Feb 2019
Unfortunately there is no way to know how far matlabFunction has progressed. The key work is done inside of MuPAD. If you know what you are looking for inside matlabFunction.m then you can tell the difference between it spending time generating the initial code, versus it spending time optimizing the code (which only happens with 'File' output), but both of those are MuPAD calls that you cannot see into.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!