Deselect table cells

3 visualizaciones (últimos 30 días)
Ocram
Ocram el 12 de Sept. de 2011
Respondida: Michael B el 15 de Abr. de 2016
Hi everybody, I have been working at a project for an exam.
My GUI is formed by 2 popup menu and one table. When I chose an option in the first popup menu, i get others fields in the second popup so that the first one is called CHAPTERS and the second one BLOCKS. Each chapter has specific blocks ( in particular not the same number... maybe the first chapter has 10 blocks or possible options that can be chosen, while the second chapter can have only 3 choices).
Now, when I chose a field in the second popup, i should obtain a list of names in the table. Then when I click over one name in the table, an edit-box is updated and shows the item selected. If I pick another item of the same view, or I might say of the same block I do not have any problem and the editbox is correctly updated. Instead, clicking on another block in the second popup, I get an error, but the table is updated correctly and I can chose the name.
It's strange, because the process works out. But I get an error in the CellSelection Callback. I think that the problem is when I change table, because the cell previously selected disappear.
Can anyone help me!!
I spent an entire day over this error...
Thanks.
  1 comentario
Jan
Jan el 12 de Sept. de 2011
Please post the complete error message and the relevant lines of code. We do not have crystalballs to guess such details.

Iniciar sesión para comentar.

Respuestas (4)

Ocram
Ocram el 12 de Sept. de 2011
ERROR:
??? Attempted to access handles.selectedCells(1); index out of bounds because numel(handles.selectedCells)=0.
Error in ==> ICD10_GUI>uitable1_CellSelectionCallback at 918
patologia_code= tableData(handles.selectedCells(1),1)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> ICD10_GUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)ICD10_GUI('uitable1_CellSelectionCallback',hObject,eventdata,guidata(hObject))
??? Error using ==> waitfor
Error while evaluating uitable CellSelectionCallback

Ocram
Ocram el 12 de Sept. de 2011
This is the Callback:
% --- Executes when selected cell(s) is changed in uitable1. function uitable1_CellSelectionCallback(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) currently selecteds % handles structure with handles and user data (see GUIDATA) %every time the cell selection changes, we update this data %eventdata stores the indices of the selected cells
handles.selectedCells = eventdata.Indices;
tableData = get(handles.uitable1,'data');
patologia_code= tableData(handles.selectedCells(1),1) patologia_name= tableData(handles.selectedCells(1),2)
patologia_code= char(patologia_code) patologia_name= char(patologia_name)
patologia_stringa= [patologia_code, ' - ', patologia_name]
set(handles.PATOLOGIA_BOX, 'String', patologia_stringa)
handles.selectedCells= []
guidata(handles.figure1,handles)

Ocram
Ocram el 13 de Sept. de 2011
Do you have any idea?
I'm trying to find it.... but it seams so strange. I guess the cellselection callback keeps the selected cell, and when I load other values the selection disappear giving me this error....
I really don't know!!
  1 comentario
Walter Roberson
Walter Roberson el 13 de Sept. de 2011
I am not at all certain as I rarely use uitable(), but I think I might have read the the cell selection callback function is called upon initialization of the table, at a time when nothing is selected.
Your callback should check isempty(handles.selectedCells) and do something gracefully for that case.

Iniciar sesión para comentar.


Michael B
Michael B el 15 de Abr. de 2016
I know this was asked a long time ago, but just in case other folks (like myself) run into this problem in the future, 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 eventdata.Indices directly will return 0 because it 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 double 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.

Categorías

Más información sobre Matrix Indexing 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!

Translated by