delete row by clicking UITABLE
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
dario cecchetti
el 15 de Dic. de 2018
Comentada: Cristian Martin
el 23 de Mayo de 2022
Hi everybody,
once the row of the table has been selected with the mouse I would like to delete it with the delet row button.
When I push delet button I can't select the Indices. Matlab shows me the following answer:
Index =
1×0 empty double row vector
Struct contents reference from a non-struct array object.
The following code:
function varargout = tabella(varargin)
% TABELLA MATLAB code for tabella.fig
% TABELLA, by itself, creates a new TABELLA or raises the existing
% singleton*.
%
% H = TABELLA returns the handle to a new TABELLA or the handle to
% the existing singleton*.
%
% TABELLA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TABELLA.M with the given input arguments.
%
% TABELLA('Property','Value',...) creates a new TABELLA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tabella_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tabella_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help tabella
% Last Modified by GUIDE v2.5 15-Dec-2018 17:52:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tabella_OpeningFcn, ...
'gui_OutputFcn', @tabella_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before tabella is made visible.
function tabella_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 tabella (see VARARGIN)
% Choose default command line output for tabella
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tabella wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tabella_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 add_row.
function add_row_Callback(hObject, eventdata, handles)
% hObject handle to add_row (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.uitable4, 'data');
data(end+1,:)={''};
set(handles.uitable4, 'data', data);
% --- Executes on button press in delete_row.
function delete_row_Callback(hObject, eventdata, handles)
% hObject handle to delete_row (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.uitable4,'CellSelectionCallBack',@(h,e) set(h,'UserData',e))
D=get(handles.uitable4,'Data');
Index=get(handles.uitable4,'UserData')
D(Index.Indices(:,1), :) = [];
set(handles.uitable4,'Data',D);
0 comentarios
Respuesta aceptada
Adam Danz
el 15 de Dic. de 2018
The UserData does not contain the index of the cell selection. To get the index of your cell selection you need to use the 2nd input to the callback function. See below.
Assuming delete_row_Callback() is a cell selection callback function, hObject is the first input, eventdata is the second input,
D=hObject.Data;
Index=eventdata.Indices;
D(Index(1), :) = [];
hObject.Data = D;
11 comentarios
Cristian Martin
el 23 de Mayo de 2022
D=hObject.Data;
Index=eventdata.Indices;
D(Index(1), :) = [];
hObject.Data = D;
How can I make this job works from a pushbutton?
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!