- you could get higher performance by moving the loop inside of some_function, so as to reduce the number of function calls
- otherwise, it depends what is being calculated inside the function. The kind of code you are using is similar to what would be used to "filter" a signal, and if you can rewrite to use filt() or filtfilt() then that might be faster -- if the processing can be written in terms of derivatives or in terms of examining previous time steps. Also, if the computation is in terms of derivatives or timesteps, then Control System Toolbox transfer functions or state space models are sometimes good representations.
- But there are certainly some computations that filter() and transfer functions are irrelevant for. There just might not be any useful speed improvement (other than running the calculation inside of one function to save on the function calls.)
improve for loop performance
3 views (last 30 days)
Walter Roberson on 20 Sep 2022