I have many excel files (540 files) which I used this code to import them to Matlab:
D = 'C:\Users\Behzad\Desktop\New folder (2)';filePattern = fullfile(D, '*.xlsx');file = dir(filePattern);x={};for k = 1 : numel(file) baseFileName = file(k).name; fullFileName = fullfile(D, baseFileName) x{k} = readtable(fullFileName); fprintf('read file %s\n', fullFileName);end
After doing that x is a 1*540 cell which contains 540 tables. I want to apply this code below for all these tables:
T = readtable(filename);sort = sortrows(T, 8);selected_table = sort (:, 8:9); dt1 = datetime([1982 01 01]);dt2 = datetime([2018 12 31]);allDates = (dt1 : calmonths(1) : dt2).';allDates.Format = 'MM/dd/yyyy';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'})
I don't know how to do that. I guess I should use the loop again but haven't any idea how to do it.
Best Regards
Best Answer