Keep data when adding/removing rows to 'uitable'

1 view (last 30 days)
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.

Accepted Answer

David (degtusmc)
David (degtusmc) on 5 Sep 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.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!