I can't run your code but here are some feedback at first glance.
First, always use correct indentation so that it's much easier to read the code. "Smart indentation" can be done by selecting all of the code and pressing ctrl+i.
See my 3 notes within your code.
dt1 = datetime([1982 01 01]);
dt2 = datetime([2018 12 31]);
allDates = (dt1 : calmonths(1) : dt2).';
allDates.Format = 'MM/dd/yyyy';
T2 = cell(size(x);
for idx = 1:numel(x)
T = readtable(idx);
sort = sortrows(T, 8);
selected_table = sort (:, 8:9);
tempTable = table(allDates(~ismember(allDates,selected_table.data)), NaN(sum(~ismember(allDates,selected_table.data)),size(selected_table,2)-1),'VariableNames',selected_table.Properties.VariableNames);
T2 = outerjoin(sort,tempTable,'MergeKeys', 1);
T2 = fillmissing(T2, 'next', 'DataVariables', {'lat', 'lon', 'station_elevation'})
end
Now, to access table #n, T2{n}
As I said, I can't run your code so if you come across problems, show me the updated code and describe what went wrong.
Also, it would be a very wise investment of your time to spend 1/2 an hour teaching yourself how to debug code using debug mode.
Best Answer