Why is matlabFunction so slow?

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 comentario

Walter Roberson
Walter Roberson el 8 de Feb. de 2019
For whatever it is worth, on my late 2013 iMac running R2018b, the above takes less than 8 seconds.

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 27 de Jul. de 2011

2 votos

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.

3 comentarios

Sujit Nair
Sujit Nair el 27 de Jul. de 2011
Movida: Dyuman Joshi el 6 de Abr. de 2024
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.
Jan
Jan el 27 de Jul. de 2011
Movida: Dyuman Joshi el 6 de Abr. de 2024
You got me. There is in fact a MATLAB function which is called matlabFunction. Sorry, I do not have the Symbolic toolbox.
Daniel Shub
Daniel Shub el 27 de Jul. de 2011
Movida: Dyuman Joshi el 6 de Abr. de 2024
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

Iniciar sesión para comentar.

Giovanni
Giovanni el 27 de Jul. de 2011

0 votos

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!

4 comentarios

John Smith
John Smith el 28 de Abr. de 2018
Oh no, It's absolutely realistic! I've been waiting 9.5 hours for matlabFunction to finish (just been curious how much will it go). Want to see the 700kb file it produced?
Walter Roberson
Walter Roberson el 28 de Abr. de 2018
John Smith: Are you possibly using matlabFunction with the 'file' option? By default using 'file' turns on sub-expression optimization, which can take a while (every sub-expression has to be compared to every other, unless you can manage it through some kind of hashing scheme.)
Qt1 Dlmr
Qt1 Dlmr el 8 de Feb. de 2019
Is tere any way to know where it is in this process at some point (callback or something..) ?
Because I just would like to know it is going to take hours or 10^80 years at the moment...
Walter Roberson
Walter Roberson el 8 de Feb. de 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.

Iniciar sesión para comentar.

Preguntada:

el 27 de Jul. de 2011

Movida:

el 6 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by