How to access all .m files in different subfolders?
Show older comments
As my project grows, I came up with the idea to arrange the different functions into different folders. For example the solvers are in the "solver" folder, the utility functions in the "utilities" folder, etc. If I invoke my functions, the do not see each other because of being different folders. How can I eliminate this error? I would like to maintain this several-folders structure. Do I have to change the current directory all the time?
Thanks, Zoli
Accepted Answer
More Answers (2)
Aldo Amaya
on 7 Jul 2014
4 votes
If you are only calling functions you do not have to change to a current directory. You just need to set the path to include all folders.
Environment>Set Path>Add With Subfolders> (Select work folder)
Then you should be able to call upon any function in your path.
5 Comments
Aldo Amaya
on 7 Jul 2014
Do not forget to save your path. Also if you add additional subfolders just repeat process.
Zoltán Csáti
on 7 Jul 2014
Edited: Zoltán Csáti
on 7 Jul 2014
Aldo Amaya
on 7 Jul 2014
After you saved your path, and tried to call the function, what was the error it gave you?
Zoltán Csáti
on 7 Jul 2014
Aldo Amaya
on 7 Jul 2014
Sounds good.
benjamin rinauto
on 18 Oct 2016
0 votes
It sounds like this file on the file exchange is what you're looking for:
https://www.mathworks.com/matlabcentral/fileexchange/59815-addcontainingdirandsubdir--
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!