Computational cost of the commanda 'path'

4 views (last 30 days)
I have a main matlab code, in which there are some scripts. In each of these scripts there are 'path' commands that direct matlab to take some scripts in other directories. My matlab version is 2021b.
I noted (by using "run code and profile command") that almost 90% of the total execution time is due to the 'path' command.
Is there any way to reduce this time? or it is necessary to delete 'path' command and merge all files in one directory needs?

Accepted Answer

Rik on 20 Sep 2022
Once you are at the stage where the profiler makes any sense at all, you should question why you are still using scripts instead of functions.
Having code in different folders is not a problem, as you can simply add all required folders to the path. I always do that in a block of code where I set a persistent variable, so the addpath function is called only once for each function.

More Answers (0)


Find more on Performance and Memory 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!

Translated by