Modifying data in uitable causes CellSelectionCallback to execute and throw error -How do I prevent this?

조회 수: 1 (최근 30일)
I have a UI table which populates other UI tables with data based on which row is currently selected, using the CellSelectionCallback function. Unfortunately, when I modify or remove rows in this master UI table, MATLAB appears to execute the CellSelectionCallback function, which throws an error at one of my conditional statements. I suspect that MATLAB is deselecting whatever cell had been selected previously and this is causing the eventdata.Indices variable to become empty or no longer in a recognized format, but my efforts to put corrective conditional statements (isempty, isnull, is < 1) in there to catch this have failed to fix the problem. I've tried putting debug breakpoints in the CellSelectionCallback function to see what's going on, but for some reason MATLAB ignores them. This question was asked a number of years ago, but apparently never answered. Anyone know what kind of conditional statements I could put in the SelectionCallback that could catch this issue? Many thanks in advance!
The error message MATLAB generates is below. tab_Category is the name of the uitable, and the "if all..." function on line 97 is my conditional statement for performing normal GUI tasks:
Index exceeds matrix dimensions.
Error in KeywordInputDiag>tab_Category_CellSelectionCallback (line 97) if all(~cellfun(@isempty,temp(eventdata.Indices(1),1:2)))
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in KeywordInputDiag (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)KeywordInputDiag('tab_Category_CellSelectionCallback',hObject,eventdata,guidata(hObject))
Error while evaluating uitable CellSelectionCallback

채택된 답변

Michael B
Michael B 2016년 4월 15일
After playing around with the script I managed to figure out what was going on. When something causes the current table selection to be cleared, it automatically triggers the CellSelectionCallback function and runs any code inside. The eventdata.Indices variable that is generated by this action is a 0x2 double array. Performing an isempty check on this directly will return 0 because eventdata.Indices isn't empty, it's just an array of zero length. If anything within the CellSelectionCallback function uses the value of eventdata.Indices and doesn't have a way to handle a zero-length array as input, MATLAB will throw an error. This can be avoided simply by adding a conditional statement inside the CellSelectionCallback function that checks the length of eventdata.Indices before doing anything else.
  댓글 수: 1
joe
joe 2018년 1월 18일
Hallo Mihael B,
I have the same Problem but i i dont know how to solve it.
my code Looks like this:
function table_Diagrams_CellSelectionCallback(hObject, eventdata, handles)
row = eventdata.Indices(1);
col = eventdata.Indices(2);
assignin('base','row',row)
assignin('base','col',col)
i will be grateful, if you can help me
thank you in advance

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by