Keep data when adding/removing rows to 'uitable'

1 visualización (últimos 30 días)
Hello everyone,
This is a follow up to a question I posted previously (link below). With the help of Evan, I was able to add or remove rows to my 'uitable' depending on the number entered in an 'edit' text box. The following code achieved that:
oldData = get(handles.table_uitable,'Data')
nRows = str2num(get(hObject,'String'))
testSize = size(oldData,1)
if nRows > size(oldData,1)
dat = cell(nRows,3)
dat(1:testSize,:) = oldData
elseif nRows < size(oldData,1)
dat = oldData(1:nRows,:)
end
set(handles.table_uitable,'Data',dat)
guidata(hObject,handles)
The problem is on the sixth line when assigning the old values. I have tried multiple things with no luck. It comes down to dealing with cells or numbers. Cells are needed to get the right amount of rows, but numbers are needed when attempting to retain the old values. Any suggestions on how I can keep the old data?
Thank you in advance for any help provided.

Respuesta aceptada

David (degtusmc)
David (degtusmc) el 5 de Sept. de 2013
The method mentioned above works. The problem was that the table data was changing to numbers at some point. To fix the problem, I added a "CreateFcn" that made the data a cell from the beginning.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by