I ran into this same problem recently as well. This is a hard Matlab habit to break and none of the solutions is intuitive. My solution involves preallocating a boolean array and then looping through the actual data checking which values I need to keep. At the end I use the boolean array to filter the original.
calfiles = [] # CAL Files keepfiles = repmat([true],length(filestr)) # Files to keep for i = length(filestr):-1:1 if filestr[i][end-7:end-4] == "_CAL" calfiles = [calfiles,filestr[i]] keepfiles[i] = false # Remove CAL file from the list end end filestr = filestr[keepfiles] # Remove CAL files
