What I figured out was instead of using strtok, I used extractBetween to pull segments of the file names and store them in a cell array:
for i = 1:length(file_idx)
% decompose file name
k = strfind(curDirFiles(file_idx(i)).name,'_');
l = strfiurDirFiles(file_idx(i)).name,'.');
fileDecompose(i,1) = extractBetween(curDirFiles(file_idx(i)).name,1,k(1)-1); % "LatLon"
fileDecompose(i,2) = extractBetween(curDirFiles(file_idx(i)).name,k(1)+1,k(2)-1); % lat
fileDecompose(i,3) = extractBetween(curDirFiles(file_idx(i)).name,k(2)+1,k(3)-1); % lon
fileDecompose(i,5) = extractBetween(curDirFiles(file_idx(i)).name,k(4)+1,l(end)-1); % timeframe
% do stuff
end
This put all the unique file name elements into the array, matrix-style.
4x5 cell:
'LatLon' '34' '-103' 'tmax' 'cm1'
'LatLon' '34' '-103' 'tmax' 'cm2'
'LatLon' '34' '-103' 'tmin' 'cm1'
'LatLon' '34' '-103' 'tmin' 'cm2'
So this solved the immediate question.
For a complete follow-up, I then used Luis Mendo's hack on the "unique" function to get it to work with cell array data:https://stackoverflow.com/questions/24151853/matlab-cell-array-to-string-vector-unique
That gave me a cell array with the unique values of file name elements other than 'tmin' and 'tmax'. Then I used that unique list to build the file names back, creating two file names by manually adding in 'tmax' and 'tmin' to each unique combination, which gave me the correct pairs I needed. Then I just imported the data, averaged the values, and wrote it out to another file.