Keep data when adding/removing rows to 'uitable'

1 回表示 (過去 30 日間)
David (degtusmc)
David (degtusmc) 2013 年 7 月 15 日
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 Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by