I'm having a problem with "cd" when looping through folders. Below is the problematic part of my script:
datadir='wherethedatais';cd(datadir);dirlist=dir('sub*'); % list of different subjects
for h=1:length(dirlist)cd(dirlist(h).name)
Everything is fine until the 7th iteration of the loop when I get this error:
Error using cdCannot CD to sub0010 (Name is nonexistent or not a directory).
All the folders are named subXXXX where XXXX is 0001 to 0114.
Any ideas what might be causing this?
Best Answer