
%Create an analyze image based on user specified XYZ dimensions.  
%Sue Whitfield 

[Xlim] = spm_input('Select Xlim1, Xlim2', 2)
xlim1 = Xlim(1);  xlim2 = Xlim(2); 


[Ylim] = spm_input('Select Ylim1, Ylim2', 2)
ylim1 = Ylim(1);  ylim2 = Ylim(2); 


[Zlim] = spm_input('Select Zlim1, Zlim2', 2)
zlim1 = Zlim(1);  zlim2 = Zlim(2); 


%outname = spm_input('Select output filename ', 1, 's') 




step = 2;

tals = [];

xok = 1; yok = 1; zok = 1;

x = xlim1; y = ylim1; z = zlim1;

while (x<xlim2)
   
   
   
   while (z<zlim2)  
      
      
      while (y<ylim2)         
         tals = [tals; [x y z] ];
         
         y = y + step;
                           
      end
      
      y = ylim1;
      
      z = z + step;
         
                  
    end
      
    z = zlim1;
    
    x = x + step;
    
        
 end
 
fname = spm_input_ui('Choose output filename:',1,'s');
full_fname = fullfile(pwd,[fname '.tal']);
save(full_fname, 'tals', '-ASCII')
 
 
 mm2img(full_fname);
 