MATLAB: How can i use CellSelectionCallback correctly

cellselectioncallbackguiguidematlab guitableuitable

I had a problem when I memlilih one cell in the table to be displayed into the text edit, when I choose a cell 1 then that arises is ID = 1, Name = f, Address = f (performed in accordance with what I have chosen) But when I select cell 2, appearing instead as when I select cell 1, how do I prevent the display according to the data in cell 2?
Here is my code in function myTabel_CellSelectionCallback :
try
al= eventdata.Indices;
dataseleksi=get(handles.myTabel,'Userdata');
getdata=dataseleksi(al);
%kode=getdata{1};
[ mydata,header,no ] = Lihat()
var1=mydata(1,1);
var2=mydata(1,2);
var3=mydata(1,3);
set(handles.txtid,'string',var1);
set(handles.txtnama,'string',var2);
set(handles.txtalamat,'string',var3);
catch end

Best Answer

Alvindra - why are you using the property UserData when trying to access data in your table?
dataseleksi=get(handles.myTabel,'Userdata');
Unless something is different in your version of MATLAB, the data in the table is stored in the Data property, so the above would be replaced with
dataseleksi=get(handles.myTabel,'Data');
Then, to access a specific element/cell within that table, you can use the row and column indices from
al = eventdata.Indices;
as
cellIdcs = eventdata.Indices;
dataseleksi = get(handles.myTabel,'Data');
cellData = dataseleksi(cellIdcs(1), cellIdcs(2))
Try the above and see what happens!