Apply code on matlab files in different directories ?
2 views (last 30 days)
I want to apply the code on the .m files present in sub directories. The names of sub-directories started from 001 up to 365 in sequence. Could someone help me to write some code ? I have a very basic knowledge of Matlab scripts.
Thanks in advance!
David Sanchez on 18 Aug 2015
path(path,'newpath') adds the newpath folder to the end of the search path. If newpath is already on the search path, then path(path,'newpath') moves newpath to the end of the search path.
In your case, you should do something like this:
your_path = path where you have your sub-directories;
for k=1:365 % sub-directories started from 001 up to 365 in sequence
str = strcat(your_path,'\000); % add the temporary 000 ending
file_number = num2str(k); % convert index to string
L = length(str); % length of your path
LK = length(file_number); % length of index as string
new_path = strcat(str(1:L-LK),file_number); % full new path od kth folder
path(path,new_path) % add the kth folder to matlab path