IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
resolve_dir.m
Go to the documentation of this file.
1 %> @ingroup ioio string
2 %> @file
3 %> @brief Auxiliar to @ref mergetool.m
4 function [filenames, groupcodes] = resolve_dir(wild, trimdot, flag_image)
5 a = dir(wild);
6 n = numel(a);
7 i = 0;
8 groupcodes = {};
9 filenames = {};
10 orderref = [];
11 
12 % Resolves group code
13 for k = 1:n
14  if ~a(k).isdir
15  i = i+1;
16  filenames{i} = a(k).name;
17  idxs = find([filenames{i}, '.'] == '.');
18  if isempty(idxs)
19  code = filenames{i};
20  else
21  idx_idx_trim = max(1, length(idxs)-trimdot);
22  code = filenames{i}(1:idxs(idx_idx_trim)-1);
23  end;
24  groupcodes{i} = code;
25 
26  if flag_image
27  if trimdot < 1
28  irerror('Trimdot < 1 does not allow for file order extraction!');
29  elseif isempty(idxs)
30  irerror('No dots in filename!');
31  end;
32  try
33  orderref(i) = eval(filenames{i}(idxs(idx_idx_trim)+1:idxs(idx_idx_trim+1)-1));
34  catch ME %#ok<NASGU>
35  irerror('Error trying to find a sequential number across the filenames!');
36  end;
37  end;
38  end;
39 end;
40 
41 if flag_image
42  [vv, ii] = sort(orderref);
43  filenames = filenames(ii);
44  groupcodes = groupcodes(ii);
45 end;
function irerror(in s)
function resolve_dir(in wild, in trimdot, in flag_image)