MATLAB: Export column name along with data in excel file in GUI

guiguideimage analysisimage processingmatlab gui

Helo,
I am builing a GUI and inside my GUI I have a table data named Results_table that contains a numerical values columnwise (n,1) stored in different columns with their respective names.
Now, I was able to export these values from the table Results_table in an excel file, but I could not find a solution to export the column names too with those values.
My code for this section is:
M=get(handles.Results_table, 'Data'); % I get values from table Results_table but it only exports values, and not their respective column names
FileName = uiputfile('*.xls','Save as');
xlswrite(FileName, M); %I save stored data in M
Is there a solution to this problem? How can I export column names that are associated with those numerical values inside table Results_table?
Thanks!

Best Answer

M = get(handles.Results_table, 'Data');
Head = get(handles.Results_table, 'ColumnName');
Data = cat(1, Head, num2cell(M));
xlswrite(FileName, Data)