Selecting folders in a specific order
Show older comments
Hi everyone,
I would like to select images from a number of folders. However, the folders have to be selected in a very specific order. What I have is a folder named 'functional' which contains folder epi1, epi2, epi3, epi4, epi5, and epi6. Each of these epi folders contain images I have to process. The function below will select the folders alphabetically (i.e. epi1 then epi2 then epi3, etc). What I want to achieve is to have the folders selected in the following order: epi4, epi5, epi6, epi1, epi2, epi3. Would anyone be able to help me? Here is the function I currently have:
dire_FIX = '/Data2/Test_subject/'
filter_str = 'f'
function P=fun_load_image_data_path(Q,dire_FIX,filter_str)
n = length(Q); % Number of subjects
P = cell(n,1);
for i = 1:n,
dire=[dire_FIX Q{i} '/nifti/WM/functional/']; % go to the functional folder of each subject
lala=dir(dire); % List content of functional folder
ns = length(lala)-2; % To take out the '.' and '..'
temp_pp=[];
if (strcmp(filter_str,'mean')) % if mean BOLD get from the first session
s = 1;
dire1=[dire lala(s+2).name '/'];
P{i}.meanimg =spm_select('FPList',dire1,strcat('^',filter_str,'.*\.nii$'));
else
add_i=1;
for s=1:ns,
dire1=[dire lala(s+2).name '/'];
temp_img = spm_select('FPList',dire1,strcat('^',filter_str,'.*\.nii$'));
for ss=1:length(temp_img),
P{i}.scans{s}{ss,1} = strcat(temp_img(ss,:),',1');
P{i}.path_all{add_i,1} = strcat(temp_img(ss,:),',1');
add_i = add_i+1;
end
fn_temp = [];
fn_temp = spm_select('FPList', dire1, '^rp.*\.txt$');
P{i}.motion_param_files{s}=fn_temp;
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!