Ok, I found a solution to deselect the cells:
First of all, this requires some Java. But don’t worry, it will still look like Matlab :)
1. You will need the script findjobj from Yair Altman: TMW File-Exchange: findjobj
2. You need a handle to your table, name it mtable. Then you need a basic Java table and do some things to get the objects you need and set some properties. You can do it:
jscroll=findjobj(mtable); h=jscroll.getComponents; viewport=h(1); a=viewport.getComponents; jtable=a(1); %com.mathworks.hg.peer.ui.UITablePeer jtable.setRowSelectionAllowed(0); jtable.setColumnSelectionAllowed(0);
3. Now the more difficult part (at least it was for me): if you have a Callback for CellSelectionChanged, but you do not want to cancel it, you should disable it temporarily
set(mtable, 'CellSelectionCallback', []);
Now you can change the selection:
jtable.changeSelection(row-1,col-1, false, false); %Java-> zero ^= one <-Matlab
And now, I was expecting when the CellSelectionCallback setting returned to its original function, everything would be fine. No, that was a Callback exception. I still don't know the exact reason, but it seems to me that calling jtable.changeSelection () changes the selection and then calls the specified callback, but the caller function does not wait until this process is started. So what I tried (and I don’t know if this is the best way to do this, but it works very well) is to just pause for a second and then return Callabck back:
pause(1) set(mtable, 'CellSelectionCallback', @myOriginalFunction);
4. Now one more thing: my goal was to change the selection to another cell. You must deselect. I don't know anything about Java components, but I was able to just set the row / column parameter to -1:
jtable.changeSelection(-1,-1, false, false);
Finally, I was able to solve this problem using a lot of explainable on undocumentedmatlab.com and other posts. I'm not sure if all the lines are needed for the call. Note that this will only be available for the documented Matlab-uitable, which appears first in version 2008 (a or b, I'm not sure about that).
EDIT There are many other functions / parameters, etc. that you can use that are undocumented. To see what is possible, you can take a look at autocomplete. Just use it on jtable. and Tab will display them. For documentation on these elements, you should probably look for a Java document.
Just a small “dynamic” minimal example (wait 3 seconds to see the change ;-)):
function startUitable() xDat=ones(5,3); h=figure('Tag','TestFigure'); mtable=uitable('Tag','TestUITABLE'); rowField=uicontrol('units','normalized','Style','edit','Position',[0.4 0.9 0.1 0.1],'parent',h,'Tag','rowField'); colField=uicontrol('units','normalized','Style','edit','Position',[0.6 0.9 0.1 0.1],'parent',h,'Tag','colField'); set(mtable, 'Units','normalized','Position',... [0.01 0.01 0.8 0.8], 'Data', xDat,... 'ColumnEditable', [false, false,false],... 'ColumnWidth', 'auto') myButton=uicontrol('units','normalized','Style','pushbutton','parent',h,'Position',[0.04 0.9 0.3 0.1],'String','change Selection') set(myButton,'Callback',@changeSelection) end function changeSelection(~,~,~) mtable=findobj('Tag','TestUITABLE'); jscroll=findjobj(mtable); h=jscroll.getComponents; viewport=h(1); a=viewport.getComponents; jtable=a(1); %com.mathworks.hg.peer.ui.UITablePeer % jtable.setRowSelectionAllowed(0); % jtable.setColumnSelectionAllowed(0); row=str2num(get(findobj('Tag','rowField'),'String')); col=str2num(get(findobj('Tag','colField'),'String')); jtable.changeSelection(row-1,col-1, false, false); end