Salam 3lykum!
Generally, you should do what rayryeng suggested in his comment, which may be done like this:
cd(fullPathOfTheFolderWithTheTxtFiles);
filenames0 = dir('*.txt');
filenames0 = {filenames0.name}'; ...'//See documentation of dir.
See: cd
, dir
.
However, if you are interested in how a list of filenames can programmatically be generated, I'm providing the following answer.
I am assuming that all possible combinations for filenames exist for k+
, k-T
and K-D
.
For the sake of explanation, let's define 3 vectors as follows:
k_plus =[0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
K_minus_T = [1e-6 0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
K_minus_D = [1e-6 0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
What I'll do first is to generate a list of all possible combinations of these vectors:
sets = {k_plus, K_minus_T, K_minus_D};
[x,y,z] = ndgrid(sets{:});
cartProd = [x(:) y(:) z(:)];
Next you can either write a loop, or do this with a slightly less easy to read vectorized version:
%// Loop Version:
nFiles = size(cartProd,1);
filenames1{nFiles,1}=[]; %// Preallocation
for ind1=1:nFiles
filenames1{ind1} = ['MTN100_' ...
'k+' num2str(cartProd(ind1,1)) '_' ...
'k-T' num2str(cartProd(ind1,2)) '_' ...
'k-D' num2str(cartProd(ind1,3)) '_' ...
'GTP0.txt'];
end
%// Vectorized Version:
filenames2=cellstr([repmat('MTN100_k+',[nFiles,1]) num2str(cartProd(:,1)) ...
repmat('_k-T',[nFiles,1]) num2str(cartProd(:,2)) ...
repmat('_k-D',[nFiles,1]) num2str(cartProd(:,3)) ...
repmat('_GTP0.txt',[nFiles,1])]);
Then you could loop over the resulting array and do whatever you need with the files.
Alternatively, if you want to find the filename of a specific combination of values, you could use something like this:
kP_wanted = k_plus(4);
kT_wanted = K_minus_T(9);
kD_wanted = K_minus_D(2);
filenames{intersect(intersect(find(cartProd(:,1)==kP_wanted),...
find(cartProd(:,2)==kT_wanted)),...
find(cartProd(:,3)==kD_wanted))}