MATLAB: How do i combine multible excel file into single file using matlab

MATLAB

Dear experiences …
I have many excel file in certain folder 100+ (D:\source), where these files are named in the following structre {0.xlsx, 1.xlsx,2.xlsx, ….etc}, all excel files havin the following columns contents look like the following ..
No Index File Name
1 6 2012-07-20-18-23-02
2 7 3097-success-edit
3 8 2012-07-20-18-30-44
4 11 2012-large-columns
5 13 2012-admins-logs
etc..
so i need to combine all these files into single excel file involve the following contents:
Id Index File Name file_label
1 6 2012-07-20-18-23-02 0
2 7 3097-success-edit 0
3 8 2012-07-20-18-30-44 0
4 11 2012-large-columns 1
5 13 2012-admins-logs 1
where ID here is numeric count for the rows, index whatever extracted from every excel file, File name whetever extracted from every file, and finally labels is give value based on file name, in the above example for the file names that extracted from 0.xlsx file its give an (0) values to all file names that comes from this 0.xlsx file, and (1) for the file names that comes from 1.xlsx file, and (2) for the file names that come from 2.xlsx file and so on..
i would thank any one can help me in this issue.
thanks

Best Answer

Assuming your excel files all have consistent header, this should be fairly simple to achieve:
path = 'D:\source';
files = dir(fullfile(path, '*.xlsx'));
result = table();
for fidx = 1:numel(files)
filecontent = readtable(fullfile(path, files(fidx).name));
[~, filenumber] = fileparts(files(fidx).name);
filecontent.file_label = repmat(str2double(filenumber), height(filecontent), 1);
result = [result; filecontent];
end