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

조회 수: 1 (최근 30일)
D
D 2013년 11월 11일
댓글: imene. B 2016년 7월 11일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by