Error set data of table by using eventdata.Indices inside CellSelectionCallback

2 views (last 30 days)
Hallo everyone,
this Error Shows up only after using set(handles.table,'Data',data):
Index exceeds matrix dimensions.
Error in GUI1>table_CellSelectionCallback (line 3197)
row_s = eventdata.Indices(1,1);
table has two columns (students and presence ) and rows(depending on how many Student in the class. let's say 10).
what i want is: if the the teacher clicks on the name of any Student (column student), on the table (cloumn presence) should marked true.
this my code Looks like:
function table_CellSelectionCallback(hObject, eventdata, handles)
row_s = eventdata.Indices(1,1);
col_s = eventdata.Indices(1,2);
%row_s = eventdata.Indices(1); % I tried this too, it gave the same Error
%col_s = eventdata.Indices(1); % I tried this too, it gave the same Error
data=eventdata.Source.Data
data(row_s,(col_s+1))={[true]}; % or olny true witout {[]} is the same result
% data(row_s,(col_s+1))=true; % tried this too, it gave the same result (Error)
set(handles.table,'Data',data)
I appreciate any help

Accepted Answer

joe
joe on 13 Feb 2018
hi everyone,
i solved that Problem and here is how i did that.
if someone wants to click on any casket of the table and get its indices and make a changes(somewhere with a Funktion on the the same table) and set that table, he should use CellEditCallBack instead of CellSelectionCallback to avoid that Problem which is:
Index exceeds matrix dimensions.
Error in GUI1>table_CellSelectionCallback (line 3197)
row_s = eventdata.Indices(1,1);
Note: the column, which you wanna click on, should be Editable.
so you should first set the column. set(handles.table.'ColumnEditable', 'On')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!