Keep data when adding/removing rows to 'uitable'

2 次查看(过去 30 天)
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.

采纳的回答

David (degtusmc)
David (degtusmc) 2013-9-5
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by