Is it more efficient to pass an array to a function? Or to generate the (very simple) array for each call?
Show older comments
I have a function that will be called many times (it is used by an ode solver). Is it more time efficient to pass the variables x and y to it, and then generate
linspace(0,x,y)
from within, or to pass linspace(0,x,y) to the function?
Is there a general answer or rule of thumb?
1 Comment
Rena Berman
on 18 Jul 2017
(Answers Dev) Restored edit
Answers (1)
Walter Roberson
on 29 Jun 2017
0 votes
Passing something as a parameter is the second fastest form of variable access, slower only than accessing a variable previously defined in the same function. It is certainly faster than re-creating the array.
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!