>> which time
>> which day
Better to not alias builtin/ML-supplied functions...changed names below.
useries = ;
No way to tell what you really want for the time ranges but
time_range = datenum_array(32:12);
will return a null array as the indexing colon expression is equivalent to 32:1:12 which is an increasing difference of +1 over a decreasing interval which is empty. That is undoubtedly the biggest cause of your problems.
Set a time value and use logical indexing within in similar as demonstrated for lat, lon except using datetime
lon = ncread(filename,'lon');
lat = ncread(filename,'lat');
ucom = ncread(filename,'U10M');
umean = nanmean(ucom,3);
U10(:,:,d) = umean;
Ubox = U10(lon_range,lat_range,time_range);
umean2 = nanmean(nanmean(nanmean(Ubox)));
useries = [useries,umean2];
Above presumes all files have same lat, lon and time data so the result of the locations will be same length--otherwise, the concatenation will fail on mismatched sizes.
Would be more efficient to determine that number first and then preallocate and store, but presuming the number of files is relatively small, the extra overhead of dynamic allocation may not be excessive and worth the extra coding.
iswithin is my "syntactic sugar" utility routine:
flg= (x>=lo) & (x<=hi);
which just moves the logical into a function for somewhat cleaner code at the user level.