Make directories for every subject
    6 views (last 30 days)
  
       Show older comments
    
    Leonore Unknown
 on 15 Jun 2015
  
    
    
    
    
    Answered: Henric Rydén
      
 on 15 Jun 2015
            Hi there! I am a real beginner here, so my question might be very stupid to you.. So I did a general analysis (batch in SPM) for one subject. Now I have the script in matlab for one subject, but I need to loop around it for all 33 subjects I have. Thing is, I need to make a new directory for every subject separately and that it stored my data for every subject in each separate folder. My loop runs through the whole code like this:
subjects = [1:18, 20:23, 25:35]; 
for s = 1:numel(subjects)
      subj = subjects(s);
%rest of the code...
  end;
I now need to make a separate loop inside this loop, so it makes a new directory for each subject and stay in that directory to save the data but leave it again for the next subject. Can someone give an example of how I would do this, where I would name each separate folder PPI_S(subjects), where subjects should contain the number of the particular subject? Thanks a bunch!
0 Comments
Accepted Answer
  Henric Rydén
      
 on 15 Jun 2015
        subjects = [1:18, 20:23, 25:35]; 
pathprefix = 'PPI_S';
for s = 1:numel(subjects)
      subj = subjects(s);
      dirname = [pathprefix num2str(subj)]
      mkdir(dirname); % Note that this will create the directory in the current path
      cd(dirname); % Change directory to the new one.
        % do some stuff and save it here
        cd('..') % Leave the subject directory
  end
0 Comments
More Answers (0)
See Also
Categories
				Find more on File Operations 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!
