GUI 'uitable' with option to add rows using push button

I want to create an editable gui table which has a fixed number of columns (17) but variable number of rows (intially all entries should be zero) where new rows of zeros can be added using a push button. I want a user to be able to edit the entries in the table and then for these to be converted into a matrix. Any help would be greatly appreciated!
So far...
% --- Executes just before DB_table is made visible.
function DB_table_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to DB_table (see VARARGIN)
% Choose default command line output for DB_table
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DB_table wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DB_table_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)

 採用された回答

Doug Hull
Doug Hull 2013 年 11 月 11 日

0 投票

Add button to your code of this form: handles.uitable is the handle to your uitable.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = get(handles.uitable, 'data');
data(end+1,:) = 0;
set(handles.uitable,'data',data)

4 件のコメント

D
D 2013 年 11 月 11 日
Thanks for replying! But I get an error of the form
Conversion to cell from double is not possible.
Error in DB_table>pushbutton1_Callback (line 83) data(end+1,:) = 0;
and I'm not sure how to fix that.
Also any suggestions on how to convert the table entries into a matrix?
D
D 2013 年 11 月 11 日
No need sorted it out. Thanks a lot!
Z Chen
Z Chen 2014 年 8 月 1 日
how did you sort it out?
imene. B
imene. B 2016 年 7 月 11 日
he puted this
data(end+1,:)={0};

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

D
D
2013 年 11 月 11 日

コメント済み:

2016 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by