I'm working at GUI in MATLAB application.
I use uitable
object. Then I find interesting undocumented feature how to sort it's data, select whole row and etc.
I do this way:
% create jhandle to my uitable object
juiTable = findjobj(handles.uitable1,'class','UIScrollPane');
jtable = juiTable(1).getComponent(0).getComponent(0);
%... some my action like this:
jtable.setRowSelectionAllowed(true);
%...
%and now lets try use callback for selected cell in uitable:
juiFunHandle = handle(jtable, 'CallbackProperties');
set(juiFunHandle, 'MousePressedCallback', @CellSelectionCallback);
set(juiFunHandle, 'KeyPressedCallback', @CellSelectionCallback);
That works perfectly.
Now question: how to put multiple parameters to CellSelectionCallback
?
I want this function makes some action (makes some button active etc).
For this I try to put GUI handles
to it. But how?
My CellSelectionCallback
function:
function CellSelectionCallback(juiTable, varargin)
% get it from the example
row = get(juiTable,'SelectedRow')+1;
fprintf('row #%d selected\n', row);
P.S. I see varargin
into it. So can I use multiple arguments? How to put it using my set
function??
By default, MATLAB callbacks pass two input arguments (the objec that generated the callback and some event data). If you want to pass more (or fewer) arguments to your callback, you can use an anonymous function to accept these two inputs and then call your callback with the desired inputs.
In your case, you could write your anonymous function such that you pass the handles
object as an additional input to your callback function
set(juiFunHandle, 'MousePressedCallback', ...
@(src, evnt)CellSelectionCallback(src, evnt, handles));
Then your callback would look something like:
function CellSelectionCallback(jtable, evntdata, handles)