Delete a selected row in a uitable

조회 수: 12 (최근 30일)
Cristian Martin
Cristian Martin 2022년 5월 29일
편집: Voss 2022년 5월 29일
Hi, I have this script for delete a certain row wich is selected by the user:
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);
When I perform a selection and first time push the button to delete the row, i get this error:
Attempt to reference field of non-structure array.
Error in Generator_v1>pushbutton5_Callback (line 171)
a = D(Index.Indices(:,1), :);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Generator_v1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Generator_v1('pushbutton5_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
>>
After the first attempt with this error everything works perfect, when I made a second selection it perform the action with no error.
What could that be?

채택된 답변

Voss
Voss 2022년 5월 29일
Move this line to the OpeningFcn:
set(handles.uitable4,'CellSelectionCallBack',@(h,e) set(h,'UserData',e));
Having that line in the pushbutton's Callback function means that the table's CellSelectionCallback is not set until after the pushbutton's Callback is executed at least once, which in turn means that the table has empty UserData even though a selection may have been made, because there was no CellSelectionCallback defined at the time the selection was made.
  댓글 수: 2
Cristian Martin
Cristian Martin 2022년 5월 29일
Mr. "No name" thanks a lot, I have learned a lot from all of you! You all are making a great job for the beginners community.
Voss
Voss 2022년 5월 29일
편집: Voss 2022년 5월 29일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by