MATLAB: Downloading table data to a file in GUI

fileguitable

I am trying to get the data from the table in GUI and I am getting the same error as mentioned above "Undefined function 'write' for input arguments of type 'double'."
My code goes here:
T = get(handles.uitable1, 'Data');
fullpathAndFilename = '/home/mytable.txt';
writetable(T, fullpathAndFilename);
The items in the table is shown below:
Please Help me. Thanks.

Best Answer

uitable() do not store table() objects.
The following code looks at the column names to create variables for the table objects. It does not assume that names are already present ('ColumnName' 'numbered' is valid). It does not assume that there are enough column names provided, and does not assume that any entries provided are valid unique variable names. If more headers are present than data columns then it extends the data columns.
Most of the work below is to ensure that valid headers of the right size are put in place. The actual work of creating the table and writing it is pretty short, so if you already know that your headers are valid and the right size then potentially you could make this code significantly shorter.
fullpathAndFilename = '/home/mytable.txt';
data = get(handles.uitable1, 'Data');
if ~iscell(data); data = num2cell(data); end
nc = size(data, 2);
%caution: orientation of ColumnName cell vector might not be what last set,
%MATLAB might have changed it
cn = get(handles.uitable1, 'ColumnName');
if isempty(cn) || ~iscell(cn)
cn = cell(1, nc);
end
nch = length(cn);
if nc < nch
data{end, nch} = []; %and all intermediate items also get []

nc = nch;
elseif nch < nc
cn{nc} = []; %and all intermediate items also get []
nch = nc;
end
mask = cellfun(@isempty, cn);
cn(mask) = sprintfc('var%d', find(mask)); %fill empty column names
cn = matlab.lang.makeUniqueStrings( matlab.lang.makeValidName(cn, 'ReplacementStyle', 'hex') );
T = cell2table(data, 'VariableNames', cn);
writetable(T, fullpathAndFilename);