downloading table data to a file in GUI
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Vinayak Appasaheb Bhatte
il 11 Lug 2018
Commentato: Vinayak Appasaheb Bhatte
il 11 Lug 2018
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.
0 Commenti
Risposta accettata
Walter Roberson
il 11 Lug 2018
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);
5 Commenti
Walter Roberson
il 11 Lug 2018
If you want a text file with no headers, then there is no point in using a table() object.
fullpathAndFilename = '/home/mytable.txt';
data = get(handles.uitable1, 'Data');
save(fullpathAndFilename, 'data', '-ascii')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Software Development Tools in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!