using feval or not?
12 views (last 30 days)
I have function handle myfun I need to evalute
I prefer using feval https://www.mathworks.com/help/matlab/ref/feval.html
y = feval(myfun, x1, x2)
instead of direct call
y = myfun(x1, x2)
because when reading code in the first syntax I know then myfun is a function handle, and in the second syntax there might be a confusion of what myfun is. So for readability and maintainability I prefer using feval.
Note that myfun is NOT a string or char.
I test the speed and it seems to me there is no speed penalty one way or another.
I even think the presence of feval in the code will help the parser-compiler to have specific code of evaluation this function at the compiation time and not at a decision at the runtime, so in theory feval could be faster.
Is there any argument againts using feval?
Jan on 30 Jul 2023
I do not see problems with using feval.
There have been a speed penalty in old versions, as far as I remember R2009a. But now the JIT-acceleration seems to remove the overhead automatically.