How to delete content of table data from gui ?

6 visualizaciones (últimos 30 días)
Cristian Martin
Cristian Martin el 25 de Mayo de 2022
Comentada: Cristian Martin el 26 de Mayo de 2022
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 comentario
Cristian Martin
Cristian Martin el 25 de Mayo de 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)
return
else
Path=strcat(pathname,filename);
data=readtable(Path, 'Delimiter',',');
data = table2cell(data);
set(handles.uitable1, 'Data', data);
end
guidata(hObject, handles);

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 25 de Mayo de 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 = [];
  2 comentarios
Cris LaPierre
Cris LaPierre el 25 de Mayo de 2022
For your second question, if I understand correctly, you want to append gathered values to the existing table, not replace them.
From my understanding, there is no append feature for a table. When you assign values to the Data property, it must have all values you want your table to have. Therefore, in order to append, you must first capture the existing values in a variable. You then append values to that variable. Once complete, you assign that variable to the table's data property.
Cristian Martin
Cristian Martin el 26 de Mayo de 2022
Thank you Cris !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by