How to delete content of table data from gui ?

9 views (last 30 days)
I have in my GUI a table wich gather data from multiple edit text trough a button boxes:
global p;
val1 = get(handles.edit2, 'String');
val2 = get(handles.edit4, 'String');
val3 = get(handles.edit5, 'String');
val4 = get(handles.edit6, 'String');
val5 = get(handles.edit7, 'String');
val6 = get(handles.edit8, 'String');
val7 = get(handles.edit9, 'String');
val8 = get(handles.edit10, 'String');
val9 = get(handles.edit11, 'String');
val10 = get(handles.edit12, 'String');
val11 = get(handles.edit13, 'String');
val12 = get(handles.edit14, 'String');
val13 = get(handles.edit29, 'String');
valp1 = get(handles.edit16, 'String');
valp2 = get(handles.edit17, 'String');
valp3 = get(handles.edit18, 'String');
valp4 = get(handles.edit19, 'String');
valp5 = get(handles.edit20, 'String');
valp6 = get(handles.edit21, 'String');
valp7 = get(handles.edit22, 'String');
valp8 = get(handles.edit23, 'String');
valp9 = get(handles.edit24, 'String');
valp10 = get(handles.edit25, 'String');
valp11 = get(handles.edit26, 'String');
valp12 = get(handles.edit27, 'String');
valp13 = get(handles.edit30, 'String');
p.MyData = [p.MyData ; [{val1} {val2} {val3} {val4} {val5} {val6} {val7} {val8} {val9} {val10} {val11} {val12} {val13}...
{valp1} {valp2} {valp3} {valp4} {valp5} {valp6} {valp7} {valp8} {valp9} {valp10} {valp11} {valp12} {valp13}]];
set(handles.uitable1, 'Data', p.MyData);
All I want is to create a button for deleting entire content of the table like this:
tableData = get(handles.uitable1,'Data');
charLocations = cellfun(@ischar, tableData);
tableData(charLocations) = {''};
tableData(~charLocations) = {[]};
set(handles.uitable1, 'Data', tableData);
The problem is after the table data's are delete it and I press the button for gather new data from forms, all the old information come back in the table including the new one. Supose that some how must to clear some buffer or something...
  1 Comment
Cristian Martin
Cristian Martin on 25 May 2022
The second problem is when I load a csv with old data into the same table, it loading well ,but when I want to gather new data in order to fill the loaded table it start a new one
code for loading csv
[filename, pathname]=uigetfile({'*.csv'}, 'Select File');
if isequal(filename,0)
data=readtable(Path, 'Delimiter',',');
data = table2cell(data);
set(handles.uitable1, 'Data', data);
guidata(hObject, handles);

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 25 May 2022
All the data returns because you likely have not cleared your variable p.MyData. You code for collecting values appends the new values to the bottom of p.MyData. To get the behavior you want, when you clear your uitable, you also need to delete values in p.MyData.
Perhaps something like p.MyData = [];

Sign in to comment.

More Answers (0)


Find more on Characters and Strings in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by