Reinstate the preallocation of the output array in the case for which no valid stations are found. Not having this causes the if ~isempty(out) a bit later to fail, bringing the whole thing crashing down (or at least stopping the script).