I'm making some guesses about what you are looking for here. The situation is that you have these files in a single directory:
And currently your code is designed to open files in order based on the file name. Something like:
for k = 1:out
fname = sprintf('123_FM%02d_HF_0221.txt')
And that only works if the filenames have contiguous numbers, because you are counting from 1 to the number of files you have found.
If that's the case, then my suggestion is to instead use the output of "dir" to operate on the files that match the pattern.
dirInfo = dir('*FM*.txt');
for k = 1:numel(dirInfo)
fname = dirInfo(k).name;
Let me know if I'm misunderstanding something though.